Skip to content

Commit d02b28b

Browse files
OdrecOdrec
authored andcommitted
fix: make speaker and confidence optional in TranscriptUtterance
- server.py: use result.get('confidence') instead of result['confidence'] to prevent KeyError when word-level data is unavailable - models.py: make TranscriptUtterance.speaker and .confidence optional since format_result() only includes them conditionally (speaker requires diarization, confidence requires word-level data) - test_models.py: add tests for utterances without speaker/confidence
1 parent 907e7a2 commit d02b28b

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

src/murmurai_server/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ class TranscriptWord(BaseModel):
105105
class TranscriptUtterance(BaseModel):
106106
"""Speaker utterance (segment) data."""
107107

108-
speaker: str
108+
speaker: str | None = None
109109
text: str
110110
start: int # milliseconds
111111
end: int # milliseconds
112-
confidence: float
112+
confidence: float | None = None
113113
words: list[TranscriptWord] | None = None
114114

115115

src/murmurai_server/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ def sync_progress_callback(progress: float) -> None:
187187
text=result["text"],
188188
words=result["words"],
189189
utterances=result["utterances"],
190-
confidence=result["confidence"],
190+
confidence=result.get("confidence"),
191191
audio_duration=result["audio_duration"],
192192
language_code=result["language_code"],
193193
progress=1.0,

tests/test_models.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,39 @@ def test_utterance_without_words(self):
165165
)
166166
assert utterance.words is None
167167

168+
def test_utterance_without_speaker(self):
169+
"""Test utterance without speaker (no diarization)."""
170+
utterance = TranscriptUtterance(
171+
text="Hello World",
172+
start=0,
173+
end=1000,
174+
confidence=0.96,
175+
)
176+
assert utterance.speaker is None
177+
assert utterance.text == "Hello World"
178+
179+
def test_utterance_without_confidence(self):
180+
"""Test utterance without confidence (no word-level data)."""
181+
utterance = TranscriptUtterance(
182+
text="Hello World",
183+
start=0,
184+
end=1000,
185+
)
186+
assert utterance.confidence is None
187+
assert utterance.speaker is None
188+
189+
def test_utterance_without_speaker_and_confidence(self):
190+
"""Test utterance with only required fields (no diarization, no word-level data)."""
191+
utterance = TranscriptUtterance(
192+
text="Test segment",
193+
start=0,
194+
end=500,
195+
)
196+
assert utterance.speaker is None
197+
assert utterance.confidence is None
198+
assert utterance.words is None
199+
assert utterance.text == "Test segment"
200+
168201

169202
class TestTranscript:
170203
"""Tests for Transcript model."""

0 commit comments

Comments
 (0)