1

[EDIT] PyAudio is not working, and the program does not do any speech recognition at all.

I'm running Ubuntu on a virtual machine and I made a short script. It uses SpeechRecognition 3.5.0 to detect what a user says. I have pyaudio installed but when I run the script I get a long error. I'm using a build in microphone on my laptop.

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

The error that I'm getting is:

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
  • 1
    Possible duplicate of [PyAudio working, but spits out error messages each time](http://stackoverflow.com/questions/7088672/pyaudio-working-but-spits-out-error-messages-each-time) – CL. Dec 20 '16 at 10:32
  • Nope. PyAudio is not in fact working. –  Dec 20 '16 at 17:46
  • You need to check if alsa works first with aplay/amixer commands and drivers are properly installed. You need to check your hardware for that (lspci output). Then you need to check if pulseaudio works with desktop settings. Once pulseaudio starts to work, everything else would be working. – Nikolay Shmyrev Dec 21 '16 at 07:54

1 Answers1

-2

I've provided the answer from their page. Basically you don't have the jack audio server running. As someone who has had to muck with Linux audio, I can tell you it can be a pain.

From https://pypi.python.org/pypi/SpeechRecognition/

On Ubuntu/Debian, I get errors like “jack server is not running or cannot be started” or “Cannot lock down […] byte memory area (Cannot allocate memory)”.

The Linux audio stack is pretty fickle. There are a few things that can cause these issues.

First, make sure JACK is installed - to install it, run sudo apt-get install multimedia-jack

You will then want to configure the JACK daemon correctly to avoid that “Cannot allocate memory” error. Run sudo dpkg-reconfigure -p high jackd2 and select “Yes” to do so.

Now, you will want to make sure your current user is in the audio group. You can add your current user to this group by running sudo adduser $(whoami) audio.

Unfortunately, these changes will require you to reboot before they take effect.

After rebooting, run pulseaudio --kill, followed by jack_control start, to fix the “jack server is not running or cannot be started” error

BretD
  • 348
  • 3
  • 12
  • Hmm... I did this, and it still gives the same error, plus another couple lines of errors. –  Dec 20 '16 at 00:14
  • 1
    Despite the recommendation in their page, this is wrong. You should NOT install jack. Jack is not a default sound server on Ubuntu, pulseaudio is. What you need to do is to configure pulseaudio and alsa properly, not install jack. – Nikolay Shmyrev Dec 20 '16 at 07:38
  • I wish I knew this earlier. Already installed Jack. Could you elaborate on how to configure pulseaudio and alsa? –  Dec 20 '16 at 17:47
  • Ignore @Nikolay, you should be using Jack and not pulseaudio, as that is what it is designed to work with. Jack is harder to configure than pulseaudio, but from their own directions they tell you to kill pulseaudio before running Jack. I'd recommend looking up some good references on configuring JACK for linux (there are plenty). Make sure you test pyaudio using one of their example programs, as that eliminates the possibility of programming error – BretD Dec 20 '16 at 21:48
  • Alright, I'll try using jack for now. Thanks for the answer! –  Dec 20 '16 at 23:32
  • Jack causes many problems with other software which do not support it. I opened in issue too https://github.com/Uberi/speech_recognition/issues/187 – Nikolay Shmyrev Dec 21 '16 at 07:50
  • I agree with Nikolay that it's a hassle, but unfortunately I think you are limited to using it. – BretD Dec 21 '16 at 19:45