guard against non-dict entries in words array

This commit is contained in:
Andy Huynh 2026-07-21 09:23:55 +07:00
parent a85061d45d
commit fd40828950
2 changed files with 6 additions and 0 deletions

View file

@ -130,6 +130,8 @@ class ElevenLabsAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
if "words" in response_json:
response["words"] = []
for word_data in response_json["words"]:
if not isinstance(word_data, dict):
continue
# Only include actual words, skip spacing and audio events
if word_data.get("type") == "word":
response["words"].append(
@ -146,6 +148,8 @@ class ElevenLabsAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
# instead of 0.
duration = 0.0
for word_data in response_json.get("words") or []:
if not isinstance(word_data, dict):
continue
try:
duration = max(duration, float(word_data.get("end") or 0.0))
except (TypeError, ValueError):

View file

@ -58,6 +58,8 @@ class TestElevenLabsTransformResponse:
"words": [
{"type": "word", "text": "hello", "start": 0.0, "end": None},
{"type": "word", "text": "x", "start": 0.0, "end": "bad"},
None,
"not-a-dict",
{"type": "word", "text": "y", "start": 0.0, "end": 2.5},
],
}