从 azure 认知语音中提取结果 id 和会话 id
Posted
技术标签:
【中文标题】从 azure 认知语音中提取结果 id 和会话 id【英文标题】:extract result id and session id from azure congnitive speech 【发布时间】:2021-12-28 16:59:32 【问题描述】:我正在尝试从 azure 认知服务语音包中提取会话 ID 和结果 ID,代码如下,我在网上尝试了很多资源,但没有任何地方提到过。
import azure.cognitiveservices.speech as speechsdk
import os
import time
path = os.getcwd()
speech_key, service_region = "", ""
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_config.speech_recognition_language="en-US"
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config)
result = ''
done = False
def stop_cb(evt):
print('CLOSING on '.format(evt))
speech_recognizer.stop_continuous_recognition()
global done
done= True
def collectResult(evt):
global result
result += evt.result.text
speech_recognizer.recognized.connect(lambda evt: collectResult(evt))
speech_recognizer.session_started.connect(lambda evt: print('SESSION STARTED: '.format(evt)))
speech_recognizer.session_stopped.connect(lambda evt: print('SESSION STOPPED '.format(evt)))
speech_recognizer.canceled.connect(lambda evt: print('CANCELED '.format(evt)))
speech_recognizer.session_stopped.connect(stop_cb)
speech_recognizer.canceled.connect(stop_cb)
speech_recognizer.start_continuous_recognition()
while not done:
print(result)
time.sleep(.5)
输出enter image description here
【问题讨论】:
【参考方案1】:您想要的两个字段是RecognitionResult.result_id 和SessionEventArgs.session_id
所以,使用上面的代码,像这样修改回调:
speech_recognizer.recognized.connect(lambda evt: print('Result ID: '.format(evt.result.result_id)))
speech_recognizer.session_started.connect(lambda evt: print('Session ID: '.format(evt.session_id)))
【讨论】:
以上是关于从 azure 认知语音中提取结果 id 和会话 id的主要内容,如果未能解决你的问题,请参考以下文章
Azure 认知服务 - 使用 python 和 websockets 自定义语音