pytohn语音识别-第一次尝试


使用pip安装SpeechRecognition, 或者 到https://pypi.org/project/SpeechRecognition/ 网站下载

import speech_recognition as sr

r = sr.Recognizer()

harvard = sr.AudioFile("common/harvard.wav")

with harvard as source:
    audio = r.record(source)

r.recognize_bing(audio, language='en-US')

报如下错误:

----------------------------------------------------------------------
TypeError                            Traceback (most recent call last)
<ipython-input-7-907481e432b8> in <module>()
----> 1 r.recognize_bing(audio, language='en-US')

TypeError: recognize_bing() missing 1 required positional argument: 'key'

提示没有key, 使用对应的接口转换语音需要到对应的站点获得key,
如果是bing, 可以在 https://azure.microsoft.com/zh-cn/services/cognitive-services/speech/ 注册获得试用api key.

r.recognize_bing(audio, language='en-US', key="1d2fec2d9b9xxxxxxc463342604a0dag")

写入key 即可获得语音文件识别后的文本.

"The stale smell of old beer lingers it takes heat to bring out the older it cold dip restore's health and zest a salt pickle taste fine with Ham tacos al pastore are my favourite zestful food is the hot cross bun."

参考文档


Author: Itaken
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source Itaken !
  TOC目录