Ubuntu16.04实现Sphinx离线语音识别

Ubuntu16.04实现Sphinx离线语音识别

 

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/boke14122621/article/details/79871224

  1. 自带Python2.7或3.0+版本都可以 使用的是3.5编译
  2. 需要安装SpeechRecognition模块
  3. 需要.wav作为测试数据

1 安装SpeechRecognition模块

pip install  SpeechRecognition` 

若是3版本则使用pip3 . 
2 安装验证

 
  1. >>> import speech_recognition as sr

  2. >>> sr.__version__

  3. '3.8.1'

还可以看看它具备属性函数 
这里写图片描述 
3 创建Recognizer实例

>>> r = sr.Recognizer()

这里写图片描述 
每个Recognizer实例有七个语音识别方法:

recognize_bing(): Microsoft Bing Speech 
recognize_google(): Google Web Speech API 
recognize_google_cloud(): Google Cloud Speech - requires installation of the google-cloud-speech package 
recognize_houndify(): Houndify by SoundHound 
recognize_ibm(): IBM Speech to Text 
recognize_sphinx(): CMU Sphinx - requires installing PocketSphinx 
recognize_wit(): Wit.ai

这次使用recognize_sphinx(),安装:

pip install PocketSphinx

如果出现以下错误: 
这里写图片描述 
输入图示命令:

sudo apt-get build-dep python-PocketSphinx

再次安装:

sudo pip install PocketSphinx --upgrade

则提示安装成功

4 使用测试

 
  1. #!/usr/bin/env python3

  2.  
  3. # NOTE: this example requires PyAudio because it uses the Microphone class

  4.  
  5. import speech_recognition as sr

  6.  
  7. # obtain audio from the microphone

  8. r = sr.Recognizer()

  9. harvard = sr.AudioFile('harvard.wav')

  10. with harvard as source:

  11. audio = r.record(source)

  12. # recognize speech using Sphinx

  13. try:

  14. print("Sphinx thinks you said " + r.recognize_sphinx(audio))

  15. except sr.UnknownValueError:

  16. print("Sphinx could not understand audio")

  17. except sr.RequestError as e:

  18. print("Sphinx error; {0}".format(e))

前期可以在解析器上一行行输入是否能运行,测试语音harvard.wav在https://github.com/realpython/python-speechrecognition/tree/master/audio_files 
可以下载。或者自己提供也行,也可以通过调用麦克风录音保存文件。

 
  1. with sr.Microphone() as source:

  2. print("Say something!")

  3. audio = r.listen(source)

5 结果 
这里写图片描述

效果其实比百度api好一些,因为是英文识别 
尝试其他的应用接口的话可以查阅其他文档。

参考: 
1.https://github.com/Uberi/speech_recognition 
2.https://realpython.com/python-speech-recognition/ 
3.http://www.mamicode.com/info-detail-93746.html 
4,https://blog.csdn.net/qiaocuiyu/article/details/52093509 
5.http://blog.itpub.net/16582684/viewspace-1243341/

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值