[編輯] PyAudio不工作,程序根本不做任何語音識別。Python語音識別錯誤ALSA
我在虛擬機上運行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
每次[PyAudio工作,但吐出的錯誤消息的可能的複製](http://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time) –
沒有。 PyAudio實際上並不工作。 – TheMCProgrammer
您需要檢查alsa是否首先使用aplay/amixer命令和驅動程序正確安裝。你需要檢查你的硬件(lspci輸出)。然後你需要檢查pulseaudio是否適用於桌面設置。一旦pulseaudio開始工作,其他一切都將工作。 –