3 from six.moves
import queue
13 """Opens a recording stream as a generator yielding the audio chunks.""" 14 def __init__(self, rate=RATE, chunk=CHUNK, server_name='127.0.0.1',
27 self.data_thread.daemon =
True 34 """Creates a socket to listen for audio data from the server.""" 35 self.
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
40 """Daemon thread that receives data from the audio socket and puts in a 41 buffer. Works just like _get_audio_data but data comes from server, 46 data = self.s.recv(self.
_chunk)
48 except KeyboardInterrupt
as e:
49 print(
"AUDIO_SERVER: Shutdown from thread: {}".format(e))
53 """Makes 3 attempts at connecting to the audio server defined in the 56 print(
"AUDIO_SERVER: Using audio server.")
58 MAX_CONNECTION_RETRY = 3
59 for _
in range(0, MAX_CONNECTION_RETRY):
62 except socket.error
as e:
63 print(
"AUDIO_SERVER: Socket exception caught!\n{}\n" 64 "Retrying...".format(e))
70 print(
"AUDIO_SERVER: Connected to audio server.")
71 self.data_thread.start()
76 raise errno.ECONNREFUSED(
"AUDIO_SERVER: Unable to connect to audio " 77 "server! Make sure it is running and you " 78 "are connected on the same network.")
81 self.data_thread.join()
94 chunk = self._buff.get()
102 chunk = self._buff.get(block=
False)
def __init__(self, rate=RATE, chunk=CHUNK, server_name='127.0.0.1', port=4444)
def __exit__(self, type, value, traceback)
def _get_server_data(self)