当前位置: 首页 > 图灵资讯 > 行业资讯> 使用SpeechRecognition进行语音识别

使用SpeechRecognition进行语音识别

来源:图灵python
时间: 2025-02-10 13:32:37

操作系统 : CentOS7.7.1908_x64

gcc版本 :4.8.5

Python 版本 : 3.6.8

语音识别环境的安装:

virtualenv-p/usr/bin/python3py36asrasrasrsrasr
sourcepy36asr/bin/activate
pipinstallSpeechRecognition
yuminstallpython3-devel
yuminstallpulseaudio-libs-devel
yuminstallalsa-lib-devel
pipinstallPocketSphinx

配置中文语音识别数据:

下载地址:

https://sourceforge.net/projects/cmusphinx/files/Acoustic%20and20language%20models/

选择: Mandarin->cmusphinx-zh-cn-5.2.tar.gz

配置数据:

cdpy36asr/lib/python3.6/site-packages/speech_recognition/pocketsphinx-data/
tarzxvfcmusphinx-zh-cn-5.2.tar.gz
mvcmusphinx-zh-cn-5.2zh-cn
cdzh-cn
mvzh_cn.cd_cont_5000acoustic-model
mvzh_cn.lm.binlanguage-model.lm.bin
mvzh_cn.dicpronounciation-dictionary.dict

测试文本:

对自然语言的理解和生成是一个多方面的问题,我们可能只是对它的部分理解。

语音识别示例:

(py36asr)[root@host60pyasrtest1#ls
test1.pytest1.wav
(py36asr)[root@host60pyasrtest1#cattest1.py
#-*-coding:utf-8-*-
#/usr/bin/python

importspeech_recognitionassr
r=sr.Recognizer()
test=sr.AudioFile("test1.wav")
withtestassource:
audio=r.record(source)
type(audio)
c=r.recognize_sphinx(audio,language='zh-cn')
print(c)
(py36asr)[root@host60pyasrtest1#pythontest1.py
李杰和申城的自然语言是一个多方面的问题,我们可能只是对他的一部分礼仪
(py36asr)[root@host60pyasrTest1#

001.jpg

本文涉及资源下载地址:https://pan.baidu.com/s/1out0tJlb_Qs-2C06_2YHOQQ

关注微信微信官方账号(聊博文)后回复 2020062101 获取提取码。

github地址:

https://github.com/mike-zhang/mikeBlogEssays/blob/master/2020/20200621_使用Speechrecognition进行语音识别.rst


更多Python相关文章,请关注Python自学网。