简体   繁体   English

speech_recognition模块卡在“说些什么”中-python

[英]speech_recognition module stuck in “say something” - python

I am trying a python script for speech recognition, i have installed the required pyaudio and SpeechRecognition modules in my enivronment. 我正在尝试用于语音识别的python脚本,我已经在我的环境中安装了所需的pyaudio和SpeechRecognition模块。

The program was running fine till yesterday, but now it is stuck in "say something". 该程序运行良好,直到昨天,但是现在被困在“说些什么”了。 Below is my code. 下面是我的代码。

import speech_recognition as sr
print "say something1"
r = sr.Recognizer()
print "say something2"
with sr.Microphone() as source:                # use the default microphone as the audio source
    print "say something3"
    audio = r.listen(source,timeout=3)                   # listen for the first phrase and extract it into audio data

print "say something"
try:
    print("You said " + r.recognize(audio))    # recognize speech using Google Speech Recognition
except LookupError:                            # speech is unintelligible
    print("Could not understand audio")

Console o/p :- 控制台o / p:-

say something1
say something2
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.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_dmix.c:1029:(snd_pcm_dmix_open) unable to open slave
say something3

Not duplicate of/ Have refferd to :- speech recognition python code not working 不重复/已转为:- 语音识别python代码不起作用

May be this can solve your problem. 也许这可以解决您的问题。

print "say something2"
with sr.Microphone() as source:                # use the default microphone as the audio source
    r.adjust_for_ambient_noise(source)  # here
    print "say something3"
    audio = r.listen(source,timeout=3)   

look at this. 看这个。 https://github.com/Uberi/speech_recognition/issues/191 https://github.com/Uberi/speech_recognition/issues/191

Last solution work for me . 最后的解决方案对我有用。 hope same work for your 希望你能做同样的工作

I have had the same problem with me, i ended up installing jack2d and pulseaudio and what not. 我也遇到了同样的问题,我最终安装了jack2d和Pulseaudio,什么也没有。

That was the problem, I then uninstalled the jack2d by running 那是问题,然后我通过运行卸载了jack2d

sudo apt-get remove --auto-remove jack

Then restarted the system, and then ran 然后重新启动系统,然后运行

jack_control  stop

Then this will give the voice input to pulse-aduio. 然后,这会将语音输入提供给pulse-aduio。

When you run the program, the console should print 运行程序时,控制台应打印

ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
ALSA lib pcm_route.c:867:(find_matching_chmap) Found no matching channel map
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock

The last lines state that Jack has stopped and the voice input is being redirected to pulse. 最后一行指出Jack已停止并且语音输入正被重定向为pulse。

what actually happening here is, the audio resoruce(mic) is being channeled only to either jack or pulse, so I uninstalled jack 实际发生的是,音频resoruce(mic)仅被引导到插孔或脉冲,所以我卸载了jack

Now my program works just fine 现在我的程序运行正常

When I tried your code as it is I got following attribute error. 当我尝试您的代码时,出现以下attribute错误。

AttributeError: 'Recognizer' object has no attribute 'recognize'

Upon going through documentation it looks like the Recognizer class don't have a method recognize . 看完文档后Recognizer类似乎没有方法可recognize you will need to use one of the several recognize_* methods that recognize class offers. 您将需要使用recognize类提供的几种recognize_*方法之一。
It seems you want to use recognize_google ,so when I change your code from 看来您想使用recognize_google ,所以当我从

print("You said " + r.recognize(audio))

to

print("You said " + r.recognize_google(audio))

The code is working for me. 该代码为我工作。

I said "hello", which was recognized below. 我说了“你好”,这在下面得到了认可。

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 something1
say something2
say something3
say something
You said hello

Hope this helps. 希望这可以帮助。

I also had this problem and changing 我也有这个问题,并且不断变化

audio = r.listen(source,timeout=3)

to

audio = r.listen(source,timeout=3, phrase_time_limit=3)

solved it for me. 为我解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM