Merge pull request #3784 from pipecat-ai/mb/stt-sagemaker-finalize
Align DeepgramSageMakerSTTService finalize pattern with DeepgramSTTService
This commit is contained in:
1
changelog/3784.fixed.md
Normal file
1
changelog/3784.fixed.md
Normal file
@@ -0,0 +1 @@
|
|||||||
|
- Fixed `DeepgramSageMakerSTTService` to properly track finalize lifecycle using `request_finalize()` / `confirm_finalize()` and use `is_final` (instead of `is_final and speech_final`) for final transcription detection, matching `DeepgramSTTService` behavior.
|
||||||
@@ -368,7 +368,6 @@ class DeepgramSageMakerSTTService(STTService):
|
|||||||
return
|
return
|
||||||
|
|
||||||
is_final = parsed.get("is_final", False)
|
is_final = parsed.get("is_final", False)
|
||||||
speech_final = parsed.get("speech_final", False)
|
|
||||||
|
|
||||||
# Extract language if available
|
# Extract language if available
|
||||||
language = None
|
language = None
|
||||||
@@ -376,8 +375,12 @@ class DeepgramSageMakerSTTService(STTService):
|
|||||||
language = alternatives[0]["languages"][0]
|
language = alternatives[0]["languages"][0]
|
||||||
language = Language(language)
|
language = Language(language)
|
||||||
|
|
||||||
if is_final and speech_final:
|
if is_final:
|
||||||
# Final transcription
|
# Check if this response is from a finalize() call.
|
||||||
|
# Only mark as finalized when both we requested it AND Deepgram confirms it.
|
||||||
|
from_finalize = parsed.get("from_finalize", False)
|
||||||
|
if from_finalize:
|
||||||
|
self.confirm_finalize()
|
||||||
await self.push_frame(
|
await self.push_frame(
|
||||||
TranscriptionFrame(
|
TranscriptionFrame(
|
||||||
transcript,
|
transcript,
|
||||||
@@ -435,10 +438,12 @@ class DeepgramSageMakerSTTService(STTService):
|
|||||||
if isinstance(frame, VADUserStartedSpeakingFrame):
|
if isinstance(frame, VADUserStartedSpeakingFrame):
|
||||||
await self._start_metrics()
|
await self._start_metrics()
|
||||||
elif isinstance(frame, VADUserStoppedSpeakingFrame):
|
elif isinstance(frame, VADUserStoppedSpeakingFrame):
|
||||||
# Send finalize message to Deepgram when user stops speaking
|
# https://developers.deepgram.com/docs/finalize
|
||||||
# This tells Deepgram to flush any remaining audio and return final results
|
# Mark that we're awaiting a from_finalize response
|
||||||
|
self.request_finalize()
|
||||||
if self._client and self._client.is_active:
|
if self._client and self._client.is_active:
|
||||||
try:
|
try:
|
||||||
await self._client.send_json({"type": "Finalize"})
|
await self._client.send_json({"type": "Finalize"})
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Error sending Finalize message: {e}")
|
logger.warning(f"Error sending Finalize message: {e}")
|
||||||
|
logger.trace(f"Triggered finalize event on: {frame.name=}, {direction=}")
|
||||||
|
|||||||
Reference in New Issue
Block a user