Skip to content

Instantly share code, notes, and snippets.

Created March 22, 2016 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/01d0e1888bf282cdf477 to your computer and use it in GitHub Desktop.
Save anonymous/01d0e1888bf282cdf477 to your computer and use it in GitHub Desktop.
def audio_send_data(self):
'''records the audio data and sends it across to the clients'''
pyaudio_obj=pyaudio.PyAudio()
#record
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 40
stream=pyaudio_obj.open(format=FORMAT,channels=CHANNELS,rate=RATE,input=True,
frames_per_buffer=CHUNK)
while True:
audio_data = stream.write(CHUNK)
for client in self.clients_audio:
try:
client.send(audio_data)
except socket.error as e: # if no socket if connected
traceback.print_exc()
stream.stop_stream()
stream.close()
pyaudio_obj.terminate()
self.sock_audio.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment