fix: make QI audio sender working
This commit is contained in:
@@ -7,3 +7,4 @@ sphinx
|
||||
sphinx_rtd_theme
|
||||
pre-commit
|
||||
python-dotenv
|
||||
numpy<=1.16.6
|
||||
|
||||
@@ -39,7 +39,6 @@ class AudioCapturer(object):
|
||||
raise NotImplementedError()
|
||||
|
||||
|
||||
|
||||
class QiAudioCapturer(AudioCapturer):
|
||||
def __init__(self, sample_rate=16000, channels=1, deinterleaved=0):
|
||||
self.session = state.qi_session
|
||||
@@ -69,15 +68,13 @@ class QiAudioCapturer(AudioCapturer):
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def audio_gen(self):
|
||||
def generate_chunk(self):
|
||||
try:
|
||||
chunk = self.q.get(True, 0.1)
|
||||
return chunk
|
||||
except Queue.Empty:
|
||||
return None
|
||||
|
||||
|
||||
# Callback invoked by NAOqi
|
||||
def processRemote(self, nbOfChannels, nbOfSamplesByChannel, timeStamp, inputBuffer):
|
||||
raw_pcm = bytes(inputBuffer)
|
||||
@@ -91,10 +88,11 @@ class QiAudioCapturer(AudioCapturer):
|
||||
pcm_f32 = np.append(self.overflow, pcm_f32)
|
||||
|
||||
for i in range(len(pcm_f32) // 512):
|
||||
self.q.put_nowait(pcm_f32[i * 512 : (i + 1) * 512])
|
||||
self.q.put_nowait(pcm_f32[i * 512 : (i + 1) * 512].tobytes())
|
||||
|
||||
self.overflow = pcm_f32[len(pcm_f32) // 512 * 512 :]
|
||||
|
||||
|
||||
class StandaloneAudioCapturer:
|
||||
pass
|
||||
|
||||
@@ -108,8 +106,8 @@ class AudioSender(SocketBase):
|
||||
|
||||
self.capturer = self.choose_capturer()
|
||||
|
||||
|
||||
def start(self):
|
||||
self.capturer.setup()
|
||||
self.thread.start()
|
||||
|
||||
def close(self):
|
||||
@@ -120,7 +118,7 @@ class AudioSender(SocketBase):
|
||||
while not state.exit_event.is_set():
|
||||
chunk = self.capturer.generate_chunk()
|
||||
|
||||
if not chunk or state.is_speaking:
|
||||
if chunk is None or state.is_speaking:
|
||||
continue
|
||||
|
||||
self.socket.send(chunk)
|
||||
|
||||
Reference in New Issue
Block a user