Repository navigation
FIX: AzureSpeechAudioToTextConverter stop callback handles session_stopped events, which have no result - #3241
Merged
Conversation
…opped events, which have no result
hannahwestra25
approved these changes
Oct 16, 2026
hannahwestra25
left a comment
Contributor
There was a problem hiding this comment.
thanks for contributing!
hannahwestra25
approved these changes
Oct 19, 2026
hannahwestra25
left a comment
Contributor
There was a problem hiding this comment.
thanks for contributing!
hannahwestra25
enabled auto-merge
October 19, 2026 15:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3237 (the underlying bug from #3073).
stop_cbis connected to both the recognizer'scanceledandsession_stoppedevents, but it always readevt.result.reason.session_stoppeddelivers aSessionEventArgs, which has noresult, so every normal end of a session raisedAttributeErrorinside the callback. The SDK swallows exceptions from callbacks, andself.doneis set before the failing line, so transcription still returned its text and the error went unnoticed.The callback now reads
resultonly when the event has one. Checked againstazure-cognitiveservices-speech1.52.0:SessionEventArgshas noresult, whileSpeechRecognitionCanceledEventArgsinherits it fromRecognitionEventArgs. A session event just stops recognition and marks the conversion done, and cancellation events keep their existing reason and error-detail logging. I also updated the docstring to say which events it receives.Tests and Documentation
Two tests in
tests/unit/converter/test_azure_speech_text_converter.py, both using spec-restricted mocks as the issue suggests, since a plainMagicMockmakes up aresultattribute and hides the bug:test_stop_cb_session_stopped_event_has_no_result:MagicMock(spec=SessionEventArgs). Recognition is stopped,doneis set, and nothing is logged as a cancellation or an error. It fails onmainwithAttributeError: Mock object has no attribute 'result'.test_stop_cb_canceled_event_logs_error_details:MagicMock(spec=SpeechRecognitionCanceledEventArgs)withCancellationReason.Error. The cancellation reason and error details are still logged.The existing
test_stop_cb(EndOfStream cancellation) passes unchanged, and so does the reproduction from the issue.pytest tests/unit/converterpasses, with Python 3.11 and thespeechextra.ruff format,ruff checkandty checkpass on the changed files. No docs or notebooks changed.