python – 语音识别在ubuntu中不起作用

我正在开始一项需要将​​音频转换为文本的作品.我正在使用 python的speechrecognition库.我在github上看到了如何使用它的教程.该程序并不能通过麦克风识别我的声音.

我在ubuntu 16.04上使用python 2.7.

码:

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    r.adjust_for_ambient_noise(source)
    audio = r.listen(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))

github code link

终端输出

shivam@shivam-HP-Pavilion-15-Notebook-PC:~/Python/audio$python temp.py
ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
Say something!

之后,“说点什么!”,它继续闪烁,但我的声音无法识别.

mic settings


解决方法

我无法安装PocketSphinx模块,遇到问题.
但是,如果我使用recogn_google切换recogn_sphinx,它会为我工作.

这是您修改过的代码.

import speech_recognition as sr

# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    r.adjust_for_ambient_noise(source)
    audio = r.listen(source)

# recognize speech using Sphinx
try:
    #print("Sphinx thinks you said " + r.recognize_sphinx(audio))
    print("Sphinx thinks you said " + r.recognize_google(audio))
except sr.UnkNownValueError:
    print("Sphinx Could not understand audio")
except sr.RequestError as e:
    print("Sphinx error; {0}".format(e))

产量

Python 2.7.9 (default,Dec 10 2014,12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright","credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
Say something!
Sphinx thinks you said hello
>>>

希望这很有用.

相关文章

功能概要:(目前已实现功能)公共展示部分:1.网站首页展示...
大体上把Python中的数据类型分为如下几类: Number(数字) ...
开发之前第一步,就是构造整个的项目结构。这就好比作一幅画...
源码编译方式安装Apache首先下载Apache源码压缩包,地址为ht...
前面说完了此项目的创建及数据模型设计的过程。如果未看过,...
python中常用的写爬虫的库有urllib2、requests,对于大多数比...