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