如何将Azure Speech的默认超时从15秒更改为分钟级

fiei3ece  于 12个月前  发布在  其他
关注(0)|答案(1)|浏览(147)

所以我试图改变默认超时15秒的azure语音,但它不工作,因为它只是得到停止后,15秒,这是一个代码,我已经创建

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))

字符串
所以在这里,我尝试使用endpoint_silence_timeout_msspeech_end_detected_timeout,它只是在15秒后停止识别。
请帮助我解决这个问题,因为我已经检查了文档,它们并没有那么有用,特别是在Python的情况下。
谢谢

bxpogfeg

bxpogfeg1#

根据提供的代码,似乎您试图直接在speech_config对象上设置超时属性。但是,这些属性应该使用speech_config对象的set_property方法设置。
此外,您可以使用Speech_SegmentationSilenceTimeoutMs属性,它可以帮助使结果更长,并允许说话者在短语中有更长的停顿时间。
下面是更新后的代码片段,您可以根据自己的要求进行参考和修改:

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))

字符串
有关静音处理的更多详细信息,您可以查看此文档。
另一种解决方案是使用continues recognition代替单次识别,以获得更多的控制何时停止识别。有关详细信息和示例,您可以查看此文档。

相关问题