Handle missing rawResponse in transcription messages (#2623)

* Handle missing rawResponse in transcription messages

- Use message.get('rawResponse', {}) to safely access rawResponse field
- Default is_final to False when rawResponse is missing
- Add proper type annotations for better code clarity
- Minor import formatting cleanup

This prevents KeyError crashes when transcription messages from Daily's API
don't include the rawResponse field in edge cases.

* docs: add changelog line
This commit is contained in:
James Hush
2025-09-10 15:03:23 +08:00
committed by GitHub
parent 38f6e33f97
commit e8f60c7c6f
2 changed files with 8 additions and 6 deletions

View File

@@ -39,6 +39,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add additional fixups to Mistral context messages to ensure they meet
Mistral-specific requirements, avoiding Mistral "invalid request" errors.
- Fixed `DailyTransport` transcription handling to gracefully handle missing
`rawResponse` field in transcription messages, preventing KeyError crashes.
## [0.0.84] - 2025-09-05
### Added

View File

@@ -61,9 +61,7 @@ try:
VirtualCameraDevice,
VirtualSpeakerDevice,
)
from daily import (
LogLevel as DailyLogLevel,
)
from daily import LogLevel as DailyLogLevel
except ModuleNotFoundError as e:
logger.error(f"Exception: {e}")
logger.error(
@@ -2317,7 +2315,7 @@ class DailyTransport(BaseTransport):
"""Handle participant updated events."""
await self._call_event_handler("on_participant_updated", participant)
async def _on_transcription_message(self, message):
async def _on_transcription_message(self, message: Dict[str, Any]) -> None:
"""Handle transcription message events."""
await self._call_event_handler("on_transcription_message", message)
@@ -2329,9 +2327,10 @@ class DailyTransport(BaseTransport):
text = message["text"]
timestamp = message["timestamp"]
is_final = message["rawResponse"]["is_final"]
raw_response = message.get("rawResponse", {})
is_final = raw_response.get("is_final", False)
try:
language = message["rawResponse"]["channel"]["alternatives"][0]["languages"][0]
language = raw_response["channel"]["alternatives"][0]["languages"][0]
language = Language(language)
except KeyError:
language = None