def stream_audio(self): #self.listening = True if online server response on received_message while not self.listening: time.sleep(0.1) CHUNK = 1024 FORMAT = pyaudio.paInt16 CHANNELS = 1 RATE = 16000 print "test" p = pyaudio.PyAudio() stream = p.open(format=FORMAT, channels=CHANNELS, rate=RATE, input=True, output=True, frames_per_buffer=CHUNK) start = time.time() while self.listening: data = stream.read(CHUNK) #print data self.send(bytearray(data),binary=True) if time.time() - start > 3: # Records for n seconds self.send(json.dumps({'action': 'stop'})) return False stream.stop_stream() stream.close() p.terminate() self.listening = False self.stream_audio_thread.join() WebSocketClient.closed(self)
def closed(self, code, reason=None): WebSocketClient.closed(self, code, reason=reason) self._wrapper._ws_on_close(code, reason)