-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient (4).py
48 lines (35 loc) · 945 Bytes
/
client (4).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
import socket
import threading
import pyaudio
client = socket.socket()
host = "localhost"
port = 5000
client.connect((host, port))
p = pyaudio.PyAudio()
Format = pyaudio.paInt16
CHANNELS = 2
RATE = 44000
CHUNK = 640
input_stream = p.open(format=Format, channels=CHANNELS, rate=RATE, input=True, frames_per_buffer=CHUNK)
output_stream = p.open(format=Format, channels=CHANNELS, rate=RATE, output=True, frames_per_buffer=CHUNK)
def send():
while (True):
try:
data = input_stream.read(CHUNK)
client.send(data)
except:
break
def receive():
while (True):
try:
data = client.recv(CHUNK)
output_stream.write(data)
except:
break
while True:
t1 = threading.Thread(target=send)
t2 = threading.Thread(target=receive)
t1.start()
t2.start()
t1.join()
t2.join()