Skip to content

Commit

Permalink
Revert "Revert "only append audio if speech has started""
Browse files Browse the repository at this point in the history
This reverts commit 992ca8f.
  • Loading branch information
matthewkennedy5 committed Apr 4, 2024
1 parent 30ad985 commit f8851ed
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions openduck-py/openduck_py/response_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def __init__(
self.response_task: Optional[asyncio.Task] = None
self.interrupt_event = asyncio.Event()
self.system_prompt = system_prompt
self.speech_has_started = False

if context is None:
context = {}
Expand Down Expand Up @@ -325,10 +326,30 @@ async def receive_audio(self, message: bytes):
vad_result = self.vad(audio_16k_chunk)
if vad_result:
async with SessionAsync() as db:
if "end" in vad_result:
print("end of speech detected.")
transcription = ""
if "start" in vad_result or "end" in vad_result:
self.time_of_last_activity = time()
await log_event(db, self.session_id, "detected_end_of_speech")
if "start" in vad_result:
self.speech_has_started = True
print("Detected start of speech", flush=True)
# await log_event(
# db,
# self.session_id,
# "detected_start_of_speech",
# audio=audio_data,
# )
else:
self.speech_has_started = False
print("Detected end of speech", flush=True)
# await log_event(
# db,
# self.session_id,
# "detected_end_of_speech",
# audio=audio_data,
# )

if self.speech_has_started:
self.audio_data.append(audio_16k_np)

audio_data = np.concatenate(self.audio_data)
transcription = await _transcribe(audio_data)
Expand Down

0 comments on commit f8851ed

Please sign in to comment.