Merge pull request #2292 from richtermb/transcription-error-callback

Add on_transcription_error callback to DailyCallbacks and handle tran…
This commit is contained in:
Aleix Conchillo Flaqué
2025-07-29 11:56:02 -07:00
committed by GitHub
2 changed files with 20 additions and 0 deletions

View File

@@ -27,6 +27,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Added `set_log_level` to `DailyTransport`, allowing setting the logging level
for Daily's internal logging system.
- Added `on_transcription_stopped` and `on_transcription_error` to Daily callbacks.
### Changed
- Play delayed messages from `ElevenLabsTTSService` if they still belong to the

View File

@@ -226,6 +226,8 @@ class DailyCallbacks(BaseModel):
on_participant_left: Called when a participant leaves.
on_participant_updated: Called when participant info is updated.
on_transcription_message: Called when receiving transcription.
on_transcription_stopped: Called when transcription is stopped.
on_transcription_error: Called when transcription encounters an error.
on_recording_started: Called when recording starts.
on_recording_stopped: Called when recording stops.
on_recording_error: Called when recording encounters an error.
@@ -253,6 +255,8 @@ class DailyCallbacks(BaseModel):
on_participant_left: Callable[[Mapping[str, Any], str], Awaitable[None]]
on_participant_updated: Callable[[Mapping[str, Any]], Awaitable[None]]
on_transcription_message: Callable[[Mapping[str, Any]], Awaitable[None]]
on_transcription_stopped: Callable[[str, bool], Awaitable[None]]
on_transcription_error: Callable[[str], Awaitable[None]]
on_recording_started: Callable[[Mapping[str, Any]], Awaitable[None]]
on_recording_stopped: Callable[[str], Awaitable[None]]
on_recording_error: Callable[[str, str], Awaitable[None]]
@@ -1233,6 +1237,9 @@ class DailyTransportClient(EventHandler):
stopped_by_error: Whether stopped due to error.
"""
logger.debug("Transcription stopped")
self._call_event_callback(
self._callbacks.on_transcription_stopped, stopped_by, stopped_by_error
)
def on_transcription_error(self, message):
"""Handle transcription error events.
@@ -1241,6 +1248,7 @@ class DailyTransportClient(EventHandler):
message: Error message.
"""
logger.error(f"Transcription error: {message}")
self._call_event_callback(self._callbacks.on_transcription_error, message)
def on_transcription_message(self, message):
"""Handle transcription message events.
@@ -1834,6 +1842,8 @@ class DailyTransport(BaseTransport):
on_participant_left=self._on_participant_left,
on_participant_updated=self._on_participant_updated,
on_transcription_message=self._on_transcription_message,
on_transcription_stopped=self._on_transcription_stopped,
on_transcription_error=self._on_transcription_error,
on_recording_started=self._on_recording_started,
on_recording_stopped=self._on_recording_stopped,
on_recording_error=self._on_recording_error,
@@ -2318,6 +2328,14 @@ class DailyTransport(BaseTransport):
if self._input:
await self._input.push_transcription_frame(frame)
async def _on_transcription_stopped(self, stopped_by, stopped_by_error):
"""Handle transcription stopped events."""
await self._call_event_handler("on_transcription_stopped", stopped_by, stopped_by_error)
async def _on_transcription_error(self, message):
"""Handle transcription error events."""
await self._call_event_handler("on_transcription_error", message)
async def _on_recording_started(self, status):
"""Handle recording started events."""
await self._call_event_handler("on_recording_started", status)