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

fiei3ece  于 2023-11-21  发布在  其他
关注(0)|答案(1)|浏览(202)

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

  1. try:
  2. speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
  3. speech_config.endpoint_silence_timeout_ms = 90000
  4. speech_config.speech_end_detected_timeout = 10*60
  5. speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
  6. print("Say something...")
  7. result = speech_recognizer.recognize_once()
  8. if result.reason == speechsdk.ResultReason.RecognizedSpeech:
  9. print("Recognized: {}".format(result.text))
  10. elif result.reason == speechsdk.ResultReason.NoMatch:
  11. print("No speech could be recognized: {}".format(result.no_match_details))
  12. elif result.reason == speechsdk.ResultReason.Canceled:
  13. cancellation_details = result.cancellation_details
  14. print("Speech Recognition canceled: {}".format(cancellation_details.reason))
  15. if cancellation_details.reason == speechsdk.CancellationReason.Error:
  16. print("Error details: {}".format(cancellation_details.error_details))
  17. except Exception as ex:
  18. 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属性,它可以帮助使结果更长,并允许说话者在短语中有更长的停顿时间。
下面是更新后的代码片段,您可以根据自己的要求进行参考和修改:

  1. import azure.cognitiveservices.speech as speechsdk
  2. try:
  3. speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
  4. speech_config.set_property(speechsdk.PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, "9000")
  5. speech_config.set_property(speechsdk.PropertyId.Speech_SegmentationSilenceTimeoutMs, "2000")
  6. speech_config.set_property(speechsdk.PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, "6000")
  7. speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
  8. print("Say something...")
  9. result = speech_recognizer.recognize_once()
  10. if result.reason == speechsdk.ResultReason.RecognizedSpeech:
  11. print("Recognized: {}".format(result.text))
  12. elif result.reason == speechsdk.ResultReason.NoMatch:
  13. print("No speech could be recognized: {}".format(result.no_match_details))
  14. elif result.reason == speechsdk.ResultReason.Canceled:
  15. cancellation_details = result.cancellation_details
  16. print("Speech Recognition canceled: {}".format(cancellation_details.reason))
  17. if cancellation_details.reason == speechsdk.CancellationReason.Error:
  18. print("Error details: {}".format(cancellation_details.error_details))
  19. except Exception as ex:
  20. print("An error occurred: {}".format(ex))

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

展开查看全部

相关问题