Implement the VAD agent #10

Merged
0950726 merged 9 commits from feat/vad-agent into dev 2025-10-29 08:15:25 +00:00
2 changed files with 3 additions and 11 deletions
Showing only changes of commit 833dd6c9d4 - Show all commits

View File

@@ -53,20 +53,14 @@ class Streaming(CyclicBehaviour):
self.audio_out_socket = audio_out_socket self.audio_out_socket = audio_out_socket
self.audio_buffer = np.array([], dtype=np.float32) self.audio_buffer = np.array([], dtype=np.float32)
self.i_since_data = 0 # Used to avoid logging every cycle if audio input stops
self.i_since_speech = 100 # Used to allow small pauses in speech self.i_since_speech = 100 # Used to allow small pauses in speech
async def run(self) -> None: async def run(self) -> None:
data = await self.audio_in_poller.poll() data = await self.audio_in_poller.poll()
if data is None: if data is None:
if self.i_since_data % 10 == 0: logger.debug("No audio data received. Discarding buffer until new data arrives.")
logger.debug( self.audio_buffer = np.array([], dtype=np.float32)
"Failed to receive audio from socket for %d ms.",
self.audio_in_poller.timeout_ms * (self.i_since_data + 1),
)
self.i_since_data += 1
return return
self.i_since_data = 0
# copy otherwise Torch will be sad that it's immutable # copy otherwise Torch will be sad that it's immutable
chunk = np.frombuffer(data, dtype=np.float32).copy() chunk = np.frombuffer(data, dtype=np.float32).copy()

View File

@@ -86,9 +86,7 @@ async def test_no_data(audio_in_socket, audio_out_socket, streaming):
audio_in_poller.poll.return_value = None audio_in_poller.poll.return_value = None
streaming.audio_in_poller = audio_in_poller streaming.audio_in_poller = audio_in_poller
assert streaming.i_since_data == 0
await streaming.run() await streaming.run()
audio_out_socket.send.assert_not_called() audio_out_socket.send.assert_not_called()
assert streaming.i_since_data == 1 assert len(streaming.audio_buffer) == 0