How to change the default timeout of Azure Speech which of 15 seconds to something like in mins scale

406 views Asked by At

So i was trying to change the default timeout of 15 seconds of azure speech but its not working as expected as its just getting stopped after 15 seconds Here is a code which i have created

try:
    speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
    speech_config.endpoint_silence_timeout_ms = 90000  
    speech_config.speech_end_detected_timeout = 10*60  
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)

    print("Say something...")
    result = speech_recognizer.recognize_once()
    if result.reason == speechsdk.ResultReason.RecognizedSpeech:
        print("Recognized: {}".format(result.text))
    elif result.reason == speechsdk.ResultReason.NoMatch:
        print("No speech could be recognized: {}".format(result.no_match_details))
    elif result.reason == speechsdk.ResultReason.Canceled:
        cancellation_details = result.cancellation_details
        print("Speech Recognition canceled: {}".format(cancellation_details.reason))
        if cancellation_details.reason == speechsdk.CancellationReason.Error:
            print("Error details: {}".format(cancellation_details.error_details))

except Exception as ex:
    print("An error occurred: {}".format(ex))

So here i tried using endpoint_silence_timeout_ms and speech_end_detected_timeout its just getting stopped to recognize after 15 seconds.

Please help me about this problem as i have checked the docs and they are not that helpful especially in the case of python.

Thanks

1

There are 1 answers

0
Rishabh Meshram On BEST ANSWER

Based on the provided code, it seems you were trying to set the timeout properties directly on the speech_config object. However, these properties should be set using the set_property method of the speech_config object.

Also, you can use Speech_SegmentationSilenceTimeoutMs property that can help in make results longer and allow longer pauses from the speaker within a phrase.

Below is the updated code snippet you can refer and modify according to your requirements:

import azure.cognitiveservices.speech as speechsdk

try:
    speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
    speech_config.set_property(speechsdk.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, "9000")
    speech_config.set_property(speechsdk.PropertyId.Speech_SegmentationSilenceTimeoutMs, "2000")
    speech_config.set_property(speechsdk.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, "6000")
    speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)

    print("Say something...")
    result = speech_recognizer.recognize_once()
    if result.reason == speechsdk.ResultReason.RecognizedSpeech:
        print("Recognized: {}".format(result.text))
    elif result.reason == speechsdk.ResultReason.NoMatch:
        print("No speech could be recognized: {}".format(result.no_match_details))
    elif result.reason == speechsdk.ResultReason.Canceled:
        cancellation_details = result.cancellation_details
        print("Speech Recognition canceled: {}".format(cancellation_details.reason))
        if cancellation_details.reason == speechsdk.CancellationReason.Error:
            print("Error details: {}".format(cancellation_details.error_details))

except Exception as ex:
    print("An error occurred: {}".format(ex))

For more details regarding silence handling, you can check this documentation.

Another solution can be to use continues recognition in place of single-shot recognition to get more control when to stop recognizing. For details and example you can check this documentation.