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

原贴地址:

https://blog.csdn.net/boke14122621/article/details/79871224

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

pip install  SpeechRecognition` 
1
若是3版本则使用pip3 . 
2 安装验证

>>> import speech_recognition as sr
>>> sr.__version__
'3.8.1'
1
2
3
还可以看看它具备属性函数 
 
3 创建Recognizer实例

>>> r = sr.Recognizer()
1
2
 
每个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
1
如果出现以下错误: 
 
输入图示命令:

sudo apt-get build-dep python-PocketSphinx
1
再次安装:

sudo pip install PocketSphinx --upgrade
1
则提示安装成功

4 使用测试

#!/usr/bin/env python3

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

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
harvard = sr.AudioFile('harvard.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))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
前期可以在解析器上一行行输入是否能运行,测试语音harvard.wav在https://github.com/realpython/python-speechrecognition/tree/master/audio_files 
可以下载。或者自己提供也行,也可以通过调用麦克风录音保存文件。

with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)
1
2
3
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/
--------------------- 
作者:幸福诗歌 
来源:CSDN 
原文:https://blog.csdn.net/boke14122621/article/details/79871224 
版权声明:本文为博主原创文章,转载请附上博文链接!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值