基于Sphinx的离线语音识别应用

  1. 安装SpeechRecognition模块,安装库后调用时,库名为speech_recognition
pip install -i https://pypi.doubanio.com/simple/ SpeechRecognition
  1. 安装PocketSphinx
pip install -i https://pypi.doubanio.com/simple/ PocketSphinx

注意:如果出现无法读取音频的报错,检查一下音频的格式是否为wav。

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
harvard = sr.AudioFile(r"C:\Desktop\start.wav")
with harvard as source:
    audio = r.record(source)
# recognize speech using Sphinx
try:
    print("Sphinx thinks you said " + r.recognize_sphinx(audio))
except sr.UnknownValueError:
    print("Sphinx could not understand audio")
except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))

普通话识别

默认的r.recognize_sphinx(audio)是对输入的音频进行英语翻译,如果想要使用普通话版本的翻译,则需要到官方下载普通话语音包,但是不翻墙下载速度较慢
想要直接下载的可以到我的个人主页里下载(上传到CSDN上面的资源,下的人多了所需积分就会被自动修改然后暴涨,屑)
或者直接私信我。(我已经传到网盘,可以不用私信直接下:https://wwd.lanzout.com/ibiyeqd)

在这里插入图片描述
国外下载地址:http://sourceforge.net/projects/cmusphinx/files/Acoustic%20and%20Language%20Models/

参考:
1.使用方法https://blog.csdn.net/boke14122621/article/details/79871224
2.调用普通话方法https://blog.csdn.net/qq_32643313/article/details/99936268

22.10重新编辑:
有条件还是试试用网络的语音交互吧,百度飞桨用起来还是不错的。(以下均为命令行内容,也有python的api)

pip install paddlepaddle -i https://mirror.baidu.com/pypi/simple
pip install paddlespeech -i https://pypi.tuna.tsinghua.edu.cn/simple

paddlespeech tts --input ‘人工智能体验’ --output test.wav

paddlespeech asr --input test.wav

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐