我正在使用一个机器人与志愿者进行对话。我正在使用python3和微软的Speech SDK来转录志愿者的回答。录音和转录都是使用Speech SDK完成的,我还没有找到如何访问和保存录制的音频文件的方法。
最小代码示例:
import time
import azure.cognitiveservices.speech as speechsdk
# define callback
def handle_final_result(evt):
global stop
print('Heard:', evt.result.text)
if 'stop' in evt.result.text:
stop = True
# TODO: somehow need to save all audio up to this point
# setup speech recognizer using microphone as input
audio_config = speechsdk.audio.AudioConfig(device_name='sysdefault:CARD=Microphone')
speech_key, service_region = "your-key-here", "your-region-here"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
# setup callback and start listening
speech_recognizer.recognized.connect(handle_final_result)
speech_recognizer.start_continuous_recognition()
stop = False
while not stop:
time.sleep(0.2)
speech_recognizer.stop_continuous_recognition_async()javascript也有类似的post/response,但我一直无法在python3中使用该示例。
发布于 2020-10-01 23:48:12
目前Speech SDK没有提供用于语音转写的麦克风音频采集接口。该功能将在未来的版本中得到支持。如果您需要访问麦克风数据,目前推荐的方法是在您的应用程序中的Speech SDK之外创建麦克风流,然后使用Speech SDK的推流API将音频数据提供给语音转录。同时,您的应用程序能够捕获/处理您需要的音频。
https://stackoverflow.com/questions/64157812
复制相似问题