-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcilent.py
72 lines (56 loc) · 1.59 KB
/
cilent.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import socket
import cv2
import numpy
import sys
import pyaudio
def recvall(sock, count):
buf = b''
while count:
newbuf = sock.recv(count)
if not newbuf: return None
buf += newbuf
count -= len(newbuf)
return buf
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 2048
RECORD_SECONDS = 0.015
TCP_IP = '192.168.2.42'#'10.129.207.29'
#TCP_IP = 'localhost'
TCP_PORT = 6000
sock = socket.socket()
sock.connect((TCP_IP, TCP_PORT))
print("connect build!!!")
new_port =int( sock.recv(50).decode())
print(new_port)
#build a new connection
sock.close()
sock = socket.socket()
sock.connect((TCP_IP, new_port))
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT, channels=CHANNELS, rate=RATE, output=True, frames_per_buffer=CHUNK)
dat = sock.recv(50).decode()
#try:
while 1:
sock.send("start".encode())
stream.write(sock.recv(4096))
length = recvall(sock,16)
stringData = recvall(sock, int(length))
data = numpy.fromstring(stringData, dtype='uint8')
decimg=cv2.imdecode(data,1)###dat
decimg =cv2.resize(decimg,(360,240))
cv2.imshow("vedio",decimg)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
if cv2.waitKey(1) & 0xFF == ord('c'):
cv2.destroyAllWindows()
#mess = raw_input("輸入欲更改的像素:")
mess =input("輸入欲更改像素(如 480, 720):")
sock.send(mess.encode())
else:
sock.send("ok!".encode())
#except Exception:
# sys.exit(dat)
sock.close()
cv2.destroyAllWindows()