使用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."
参考文档
- Python语音识别终极指北,没错,就是指北!
- The Ultimate Guide To Speech Recognition With Python
- [PYTHON语音识别终极指南-帮你完成那个最难的从0到1 转 PYTHON语音识别终极指南-帮你完成那个最难的从0到1 悦动智能](http://sparkgis.com/java/2018/04/python%E8%AF%AD%E9%9F%B3%E8%AF%86%E5%88%AB%E7%BB%88%E6%9E%81%E6%8C%87%E5%8D%97-%E5%B8%AE%E4%BD%A0%E5%AE%8C%E6%- 88%90%E9%82%A3%E4%B8%AA%E6%9C%80%E9%9A%BE%E7%9A%84%E4%BB%8E0%E5%88%B01-%E8%BD%AC-python/)
- 终极指南:使用 Python 进行语音识别
- SpeechRecognition