question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Python sample speech_recognition_with_push_stream blocks long time

See original GitHub issue

Describe 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:

  1. 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
  2. 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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pankoponcommented, Apr 19, 2022

Fixed in the Speech SDK release 1.21.0 which is available now.

0reactions
pankoponcommented, Jan 21, 2022

Internal work item ref. 3712714.

Read more comments on GitHub >

github_iconTop Results From Across the Web

speech_recognizer.stop_continuous_recognition ...
I implement the speech recognition according to the "speech_recognition_with_push_stream()" method in the samples python code.
Read more >
Speech SDK audio input stream concepts - Azure AI services
The Speech SDK provides a way to stream audio into the recognizer as an alternative to microphone or file input. This guide describes...
Read more >
The Ultimate Guide To Speech Recognition With Python
The record() method, when used inside a with block, always moves ahead in the file stream. This means that if you record once...
Read more >
Azure Speech SDK Speech to text from stream using python
This stream pushes the data to SDK for each package that is received. The speech recognition with push stream is thus used in...
Read more >
Transcribe a streaming audio feed | Cloud Speech-to-Text ...
Transcribe a streaming audio feed from a microphone. ... import javax.sound.sampled.AudioFormat; ... bridging Offset accounts for time of resent audio
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found