Skip to content

Commit ceec961

Browse files
authored
fix: add universal-2 fallback for languages unsupported by universal-… (#454)
universal-3-pro does not support all languages (e.g. Dutch/nl). Setting speech_models to ["universal-3-pro", "universal-2"] lets AssemblyAI fall back to universal-2 for the 99 languages not covered by universal-3-pro. Also fetch and store the real AssemblyAI error reason in the webhook error handler instead of the generic "AssemblyAI error for transcript <id>".
1 parent f722eef commit ceec961

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

echo/server/dembrane/api/webhooks.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,15 @@ async def assemblyai_webhook_callback(
7373

7474
if normalized_status == "error":
7575
from dembrane.tasks import _on_chunk_transcription_done
76-
from dembrane.transcribe import _save_chunk_error
76+
from dembrane.transcribe import _save_chunk_error, fetch_assemblyai_result
7777

78-
_save_chunk_error(chunk_id, f"AssemblyAI error for transcript {payload.transcript_id}")
78+
error_detail = f"AssemblyAI error for transcript {payload.transcript_id}"
79+
try:
80+
fetch_assemblyai_result(payload.transcript_id)
81+
except Exception as fetch_exc:
82+
error_detail = str(fetch_exc)
83+
84+
_save_chunk_error(chunk_id, error_detail)
7985
_on_chunk_transcription_done(conversation_id, chunk_id, logger)
8086
delete_assemblyai_webhook_metadata(payload.transcript_id)
8187
return {"status": "error_handled"}

echo/server/dembrane/transcribe.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def transcribe_audio_assemblyai(
107107

108108
data: dict[str, Any] = {
109109
"audio_url": audio_file_uri,
110-
"speech_models": ["universal-3-pro"],
110+
"speech_models": ["universal-3-pro", "universal-2"],
111111
"language_detection": True,
112112
"language_detection_options": {
113113
"expected_languages": list(set(get_allowed_languages()) | {"pt"}),

echo/server/tests/test_transcribe_webhook.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _fake_post(url: str, **kwargs: Any) -> _FakeResponse:
5151
assert transcript is None
5252
assert payload == {"transcript_id": "tx-1"}
5353
assert captured["url"].endswith("/v2/transcript")
54-
assert captured["json"]["speech_models"] == ["universal-3-pro"]
54+
assert captured["json"]["speech_models"] == ["universal-3-pro", "universal-2"]
5555
assert "speech_model" not in captured["json"]
5656
assert "prompt" not in captured["json"]
5757
assert captured["json"]["keyterms_prompt"] == ["Dembrane"]
@@ -92,7 +92,7 @@ def _fake_get(_url: str, **_kwargs: Any) -> _FakeResponse:
9292
assert response["status"] == "completed"
9393
assert payloads["polls"] == 2
9494
post_payload = payloads["posts"][0]
95-
assert post_payload["speech_models"] == ["universal-3-pro"]
95+
assert post_payload["speech_models"] == ["universal-3-pro", "universal-2"]
9696
assert "speech_model" not in post_payload
9797
assert "webhook_url" not in post_payload
9898

0 commit comments

Comments
 (0)