Add on_end_of_turn event handler to AssemblyAI STT

Fires after the final transcript is pushed in both Pipecat and
AssemblyAI turn detection modes, giving users a reliable hook
that arrives after all transcript frames. Matches the existing
Deepgram Flux on_end_of_turn pattern.
This commit is contained in:
Mark Backman
2026-03-24 16:11:35 -04:00
parent b49bf1c83f
commit ddf6a41854

View File

@@ -129,6 +129,16 @@ class AssemblyAISTTService(WebsocketSTTService):
Provides real-time speech transcription using AssemblyAI's WebSocket API. Provides real-time speech transcription using AssemblyAI's WebSocket API.
Supports both interim and final transcriptions with configurable parameters Supports both interim and final transcriptions with configurable parameters
for audio processing and connection management. for audio processing and connection management.
Event handlers available (in addition to WebsocketSTTService events):
- on_end_of_turn(service, transcript): Called when AssemblyAI detects end of turn.
Example::
@service.event_handler("on_end_of_turn")
async def on_end_of_turn(service, transcript):
...
""" """
Settings = AssemblyAISTTSettings Settings = AssemblyAISTTSettings
@@ -303,6 +313,8 @@ class AssemblyAISTTService(WebsocketSTTService):
self._user_speaking = False self._user_speaking = False
self._register_event_handler("on_end_of_turn")
def _configure_pipecat_turn_mode(self, settings: Settings, is_u3_pro: bool): def _configure_pipecat_turn_mode(self, settings: Settings, is_u3_pro: bool):
"""Configure settings for Pipecat turn detection mode. """Configure settings for Pipecat turn detection mode.
@@ -741,6 +753,7 @@ class AssemblyAISTTService(WebsocketSTTService):
) )
await self._trace_transcription(transcript_text, True, language) await self._trace_transcription(transcript_text, True, language)
await self.stop_processing_metrics() await self.stop_processing_metrics()
await self._call_event_handler("on_end_of_turn", transcript_text)
else: else:
await self.push_frame( await self.push_frame(
InterimTranscriptionFrame( InterimTranscriptionFrame(
@@ -774,6 +787,7 @@ class AssemblyAISTTService(WebsocketSTTService):
# above, so ordering is preserved) and upstream. # above, so ordering is preserved) and upstream.
await self.broadcast_frame(UserStoppedSpeakingFrame) await self.broadcast_frame(UserStoppedSpeakingFrame)
self._user_speaking = False self._user_speaking = False
await self._call_event_handler("on_end_of_turn", transcript_text)
else: else:
await self.push_frame( await self.push_frame(
InterimTranscriptionFrame( InterimTranscriptionFrame(