Azure语音转文本教程

时间:2019-07-04 08:58:51

标签: azure speech-to-text

我想通过使用Azure Speech to Text将音频文件转换为文本数据。有谁知道很好的教程吗?我可以在下面找到一个教程: https://docs.microsoft.com/en-us/azure/cognitive-services/speech-service/quickstart-python

但是样本的音频源是来自麦克风而不是音频文件。

谢谢。

1 个答案:

答案 0 :(得分:0)

有一个名为whatstheweatherlike.wav的官方音频示例,您可以从GitHub Repo Azure-Samples/cognitive-services-speech-sdk的{​​{3}}获得。

这是我编写的示例代码,部分引用了官方教程samples/csharp/sharedcontent/console/whatstheweatherlike.wav。我通过1.6.0安装了用于语音的Azure认知服务SDK的当前版本pip install azure-cognitiveservices-speech

import azure.cognitiveservices.speech as speechsdk

speech_key, service_region = "<your api key>", "<your region>"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

audio_config = speechsdk.audio.AudioConfig(filename='whatstheweatherlike.wav')
speech_recognizer = speechsdk.SpeechRecognizer(speech_config=speech_config, audio_config=audio_config)
result = speech_recognizer.recognize_once()
print(result.text)

从音频样本文件中识别出的文本如下。

What's the weather like?

希望有帮助。