Skip to content

Commit 4d55a8e

Browse files
committed
Code review feedback
1 parent b0f77bc commit 4d55a8e

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • src/pipecat/services/gradium

src/pipecat/services/gradium/stt.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
raise Exception(f"Missing module: {e}")
4747

4848
SAMPLE_RATE = 24000
49+
# Seconds to wait after a "flushed" message for trailing text tokens to arrive
50+
# before finalizing the transcription.
51+
TRANSCRIPT_AGGREGATION_DELAY = 0.1
4952

5053

5154
def language_to_gradium_language(language: Language) -> Optional[str]:
@@ -202,7 +205,6 @@ def __init__(
202205
# and pushed as a TranscriptionFrame.
203206
self._accumulated_text: list[str] = []
204207
self._flush_counter = 0
205-
self._transcript_aggregation_delay = 0.1 # seconds to wait after flushed
206208
self._transcript_aggregation_task: Optional[asyncio.Task] = None
207209

208210
def can_generate_metrics(self) -> bool:
@@ -384,6 +386,9 @@ async def _disconnect(self):
384386
await self.cancel_task(self._transcript_aggregation_task)
385387
self._transcript_aggregation_task = None
386388

389+
self._accumulated_text.clear()
390+
self._flush_counter = 0
391+
387392
if self._receive_task:
388393
await self.cancel_task(self._receive_task)
389394
self._receive_task = None
@@ -457,7 +462,7 @@ async def _handle_flushed(self):
457462

458463
async def _transcript_aggregation_handler(self):
459464
"""Wait for trailing tokens then finalize the accumulated transcription."""
460-
await asyncio.sleep(self._transcript_aggregation_delay)
465+
await asyncio.sleep(TRANSCRIPT_AGGREGATION_DELAY)
461466
await self._finalize_accumulated_text()
462467

463468
async def _finalize_accumulated_text(self):

0 commit comments

Comments
 (0)