我第一次尝试示例代码
import speech_recognition as sr
r = sr.Recognizer(language = "en-US" )
r.pause_threshold = 0.6
with sr.Microphone() as source:
audio = r.adjust_for_ambient_noise(source)
print "Speak Now"
audio = r.listen(source, timeout=1) # listen for the first phrase and extract it into audio data
try:
print("You said " + r.recognize(audio)) # recognize speech using Google Speech Recognition
except LookupError: # speech is unintelligible
print("Could not understand audio")
except IndexError:
print("No internet")
except KeyError:
print("quota maxed out")
但我得到了这个
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
ALSA lib dlmisc.c:252:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_equal.so
ALSA lib dlmisc.c:252:(snd1_dlobj_cache_get) Cannot open shared library /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_equal.so
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
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
Speak now
然后它才被击中
我该怎么办?
答案 0 :(得分:1)
首先,确保输入没有静音。 其次,你可能需要杰克。
sudo apt-get install jackd
或者......你的麦克风可能无法通过Alsa和各种音频框架之一检测声音[GStreamer,PulseAudio,Phonon,OSS等]。您需要查看您正在使用的组合。我的是Alsa / PulseAudio / JACK。你没有提到你的发行版,所以你的发行版可能会有所不同。然后,您可以调整输入端口,以解决问题。
在遇到同样的问题并确保我的输入没有静音后,我下载了Pulse Audio音量控制器:
sudo apt-get install pavucontrol
您希望能够设置输入设备端口。同样,根据您的发行版和硬件,这可能有所不同:内部/外部麦克风,模拟/数字选项或OSS。这些是我的输入设备选项中的一些示例。 然后麦克风发现了我的声音。我收到了和你一样的错误信息,但程序输出是预期的。
如果你读到这个: Speech Recognition 2.0.1 您将看到相同的代码段以及如何防止显示这些警告。本文还将介绍您需要安装的所有内容。比如JACK [jackd]。
这篇文章帮助我缩小了问题的范围: How it works: Linux audio explained 它也帮助我不敢尝试从终端解决这个问题。
希望这有助于你或他人。祝你好运。