This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket, pyaudio, sys, wave, signal | |
#reset something about signals in unix systems... or something | |
signal.signal(signal.SIGPIPE, signal.SIG_DFL) | |
# network setup | |
host = socket.gethostname() | |
port = 12345 | |
chunk = 4096 | |
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
client_socket.connect((host, port)) | |
signal.signal(signal.SIGPIPE, signal.SIG_DFL) | |
# instantiate PyAudio | |
p = pyaudio.PyAudio() | |
# open stream | |
stream = p.open(format = p.get_format_from_width(2), | |
channels = 2, | |
rate = 41100, | |
output = True) | |
buffer = client_socket.recv(4096) | |
while len(buffer) > 0: | |
chunk = client_socket.recv(4096) | |
stream.write(chunk) | |
if not chunk: | |
# if we can't receive any data, then the socket has died | |
break | |
buffer += chunk | |
# stop stream | |
stream.stop_stream() | |
stream.close() | |
# close pyaudio | |
p.terminate() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment