Python sample speech_recognition_with_push_stream blocks long time
See original GitHub issueDescribe the bug
Python speech sample function speech_recognition_with_push_stream
contains line speech_recognizer.stop_continuous_recognition()
, which blocks for 10s. I guess that 10s (10 000ms) period could be a timeout, which probably expires because speech recognizer doesn’t detect, that stream has been already closed in previous step and method is blocking and waiting until stream is closed.
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/ac8c9899c4c741a836fbcd01d66b9f4fd1d06cec/samples/python/console/speech_sample.py#L453-L457
I found out and tried these scenarios:
- when I add some debug prints
stream.close()
print("Before...")
start = time.time()
speech_recognizer.stop_continuous_recognition()
print(f"After {time.time() - start}...")
output is
Before...
RECOGNIZED: SpeechRecognitionEventArgs(session_id=<session_id>, result=SpeechRecognitionResult(result_id=<result_id>, text="", reason=ResultReason.RecognizedSpeech))
After 10.02142333984375...
- when I add
time.sleep(1)
after closing the stream, it is without 10s delay
stream.close()
time.sleep(1)
print("Before...")
start = time.time()
speech_recognizer.stop_continuous_recognition()
print(f"After {time.time() - start}...")
RECOGNIZED: SpeechRecognitionEventArgs(session_id=<session_id>, result=SpeechRecognitionResult(result_id=<result_id>, text="", reason=ResultReason.RecognizedSpeech))
CANCELED SpeechRecognitionCanceledEventArgs(session_id=<session_id>, result=SpeechRecognitionResult(result_id=<result_id>, text="", reason=ResultReason.Canceled))
SESSION STOPPED SessionEventArgs(session_id=<session_id>)
Before...
After 0.0006592273712158203...
- when I replace
speech_recognizer.stop_continuous_recognition()
by async version, everything works fine without 10s delay
stream.close()
print("Before...")
start = time.time()
speech_recognizer.stop_continuous_recognition_async().get()
print(f"After {time.time() - start}...")
Before...
RECOGNIZED: SpeechRecognitionEventArgs(session_id=<session_id>, result=SpeechRecognitionResult(result_id=<result_id>, text="", reason=ResultReason.RecognizedSpeech))
SESSION STOPPED SessionEventArgs(session_id=<session_id>)
After 0.598764181137085...
To Reproduce Steps to reproduce the behavior:
- Run function
speech_recognition_with_push_stream
https://github.com/Azure-Samples/cognitive-services-speech-sdk/blob/ac8c9899c4c741a836fbcd01d66b9f4fd1d06cec/samples/python/console/speech_sample.py#L417 - It takes 10 000 ms to stop execution of the
stop_continuous_recognition
method
Expected behavior
stop_continuous_recognition
should not block so long.
Version of the Cognitive Services Speech SDK azure-cognitiveservices-speech version 1.18.0
Platform, Operating System, and Programming Language
- OS: Ubuntu 18.04
- Hardware - x64
- Programming language: Python
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top GitHub Comments
Fixed in the Speech SDK release 1.21.0 which is available now.
Internal work item ref. 3712714.