speech_recognition模块陷入“说些什么” - 蟒蛇

时间:2016-08-27 11:36:54

标签: python python-2.7 speech-recognition

我正在尝试用于语音识别的python脚本,我在我的环境中安装了所需的pyaudio和SpeechRecognition模块。

程序运行正常,直到昨天,但现在它停留在“说些什么”。以下是我的代码。

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")

控制台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

不重复/已收件人: - speech recognition python code not working

4 个答案:

答案 0 :(得分:2)

可能这可以解决您的问题。

from flask import Flask, send_from_directory

app = Flask(__name__)

@app.route("/robots.txt")
def robots():
    return send_from_directory("static", "robots.txt")

if __name__ == "__main__":
    app.run()
看看这个。 https://github.com/Uberi/speech_recognition/issues/191

最后的解决方案对我有用。希望你的工作相同

答案 1 :(得分:1)

我遇到了同样的问题,我最终安装了jack2d和pulseaudio,什么不是。

那就是问题,然后我通过运行

卸载了jack2d
sudo apt-get remove --auto-remove jack

然后重新启动系统,然后运行

jack_control  stop

然后这会将语音输入发送到pulse-aduio。

运行程序时,控制台应打印

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

最后一行说明Jack已经停止并且语音输入被重定向到脉冲。

这里实际发生的是,音频resoruce(麦克风)只被引导到插孔或脉冲,所以我卸载了插孔

现在我的程序工作得很好

答案 2 :(得分:1)

当我尝试使用您的代码时,我遇到了attribute错误。

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

通过documentation后,Recognizer类似乎没有方法recognize。您需要使用recognize_*课程提供的多种recognize方法之一 您似乎想要使用recognize_google,因此当我从

更改您的代码时
print("You said " + r.recognize(audio))

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

代码对我有用。

我说"你好",这在下面被认可。

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

希望这有帮助。

答案 3 :(得分:0)

我也遇到了这个问题,并且正在更改

index                   a          b     c        del 
2018-06-25 12:51:00    NaN        NaN   NaN       1.0
2018-06-25 12:52:00    NaN        NaN   NaN       NaN
2018-06-25 12:53:00    NaN        NaN   NaN       NaN 
2018-06-25 12:54:00    NaN        NaN   NaN       NaN 
2018-06-25 12:55:00    NaN        NaN   NaN       NaN
2018-06-25 12:56:00    NaN        NaN   NaN       NaN 
2018-06-25 12:57:00    NaN        NaN   NaN       NaN 
2018-06-25 12:58:00    0.5        0.6   0.6       0.0
2018-06-25 12:59:00    0.6        0.7   0.7       0.0
2018-06-25 13:00:00    0.6        0.8   0.6       0.0
2018-06-25 13:01:00    0.7        0.9   0.7       0.0 
2018-06-25 13:02:00    0.6        0.9   0.6       0.0

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

为我解决了。