-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
51 lines (36 loc) · 969 Bytes
/
client.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
44
45
46
47
48
49
50
51
import socket
import pyaudio
CHUNK = 8192
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
HOST = '192.168.1.112' # The remote host
PORT = 50007 # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=CHUNK)
stream.start_stream()
def main():
print("*_>recording")
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
try:
data = stream.read(CHUNK)
except Exception as e:
print(e)
data = '\x00' * CHUNK
print(len(data))
s.sendall(data)
print("*_>done recording")
stream.stop_stream()
stream.close()
p.terminate()
s.close()
print("*_>closed")
if __name__ == '__main__':
main()