-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertAudioFilesClient.py
43 lines (40 loc) · 1.01 KB
/
convertAudioFilesClient.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os.path
import socket
import pydub
FILENAME = "FILE_NAME.m4a"
s = socket.socket()
s.connect(("localhost", 8000))
filetosend = open(FILENAME, "rb")
s.send(b"FILESIZE\r\n")
print(os.path.getsize(FILENAME))
s.send(str(os.path.getsize(FILENAME)).encode() + b"\r\n")
s.send(b"FILENAME\r\n")
s.send(FILENAME.encode("utf-8") + b"\r\n")
s.send(b"CONTENT\r\n")
data = filetosend.read(1024)
print(data)
while data:
# print("Sending...")
s.send(data)
data = filetosend.read(1024)
filetosend.close()
s.send(b"\r\n")
s.send(b"EOF\r\n\r\n")
print("Done Sending.")
print(os.path.getsize(FILENAME))
print(str(os.path.getsize(FILENAME)).encode())
content = b""
file_read = False
while not file_read:
# print("Reading...")
response = s.recv(16)
content += response
if len(content) > 32 and b"\r\nEOF\r\n\r\n" in content[-32:]:
file_read = True
print("Done Reading.")
print(content)
s.shutdown(2)
s.close()
output_file = open(FILENAME[:-4] + ".wav", 'wb')
output_file.write(content[:-9])
output_file.close()