[编辑] PyAudio无法正常工作,该程序根本不进行任何语音识别。
我正在虚拟机上运行Ubuntu而且我制作了一个简短的脚本。它使用SpeechRecognition 3.5.0来检测用户说的内容。我安装了pyaudio,但是当我运行脚本时,我得到一个很长的错误。我在笔记本电脑上使用内置麦克风。
import wolframalpha
import os
from gtts import gTTS
import speech_recognition as sr
r = sr.Recognizer()
with sr.Microphone() as source:
audio = r.listen(source)
print("You said " + r.recognize(audio))
app_id = ("H34HDS-SDFJKOEER2")
client = wolframalpha.Client(app_id)
while app_id == "H34HDS-SDFJKOEER2":
input = raw_input("Question: ")
res = client.query(input)
answer = next(res.results).text
tts = gTTS(text=answer, lang='en')
tts.save("hello.mp3")
os.system("mpg321 hello.mp3")
我得到的错误是:
ALSA lib pcm_dsnoop.c:606:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib setup.c:548:(add_elem) Cannot obtain info for CTL elem (MIXER,'AC97 2ch->4ch Copy Switch',0,0,0): No such file or directory
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.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib setup.c:548:(add_elem) Cannot obtain info for CTL elem (MIXER,'AC97 2ch->4ch Copy Switch',0,0,0): No such file or directory
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib setup.c:548:(add_elem) Cannot obtain info for CTL elem (PCM,'IEC958 Playback PCM Stream',0,0,0): No such file or directory
ALSA lib setup.c:548:(add_elem) Cannot obtain info for CTL elem (PCM,'IEC958 Playback PCM Stream',0,0,0): No such file or directory
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2266:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
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
答案 0 :(得分:-2)
我从他们的页面提供了答案。基本上你没有运行插孔音频服务器。作为一个不得不使用Linux音频的人,我可以告诉你这可能是一种痛苦。
来自https://pypi.python.org/pypi/SpeechRecognition/
在Ubuntu / Debian上,我收到“杰克服务器未运行或无法启动”或“无法锁定[...]字节存储区(无法分配内存)”等错误。
Linux音频堆栈非常善变。有一些事情可能导致这些问题。
首先,确保安装了JACK - 安装它,运行sudo apt-get install multimedia-jack
然后,您需要正确配置JACK守护程序以避免“无法分配内存”错误。运行sudo dpkg-reconfigure -p high jackd2并选择“是”来执行此操作。
现在,您需要确保当前用户位于音频组中。您可以通过运行sudo adduser $(whoami)audio将您当前的用户添加到此论坛。
不幸的是,这些更改将要求您在生效之前重新启动。
重新启动后,运行pulseaudio --kill,然后执行jack_control start,修复“jack服务器未运行或无法启动”错误