fix(azure): surface speech recognition failures

Co-authored-by: ishaan-berri <ishaan-berri@users.noreply.github.com>
This commit is contained in:
oss-agent-shin 2026-05-09 00:09:57 +00:00
parent 2e5d70570e
commit 126dc2ca16
No known key found for this signature in database
2 changed files with 29 additions and 0 deletions

View file

@ -133,6 +133,17 @@ class AzureSpeechAudioTranscriptionConfig(BaseAudioTranscriptionConfig):
raw_response: httpx.Response,
) -> TranscriptionResponse:
response_json = raw_response.json()
recognition_status = response_json.get("RecognitionStatus")
if recognition_status is not None and recognition_status != "Success":
raise AzureSpeechAudioTranscriptionException(
message=(
"Azure AI Speech transcription failed with "
f"RecognitionStatus={recognition_status}."
),
status_code=raw_response.status_code,
headers=raw_response.headers,
)
text = self._extract_text(response_json)
response = TranscriptionResponse(text=text)
response._hidden_params = response_json

View file

@ -183,6 +183,24 @@ def test_azure_speech_audio_transcription_response_transform(payload, expected_t
assert result._hidden_params == payload
def test_azure_speech_audio_transcription_response_raises_on_failed_status():
config = AzureSpeechAudioTranscriptionConfig()
response = httpx.Response(
200,
json={
"RecognitionStatus": "NoMatch",
"Offset": 0,
"Duration": 0,
},
)
with pytest.raises(
AzureSpeechAudioTranscriptionException,
match="RecognitionStatus=NoMatch",
):
config.transform_audio_transcription_response(response)
def test_azure_speech_transcription_routes_through_provider_config(monkeypatch):
expected = TranscriptionResponse(text="hello")
audio_handler = MagicMock(return_value=expected)