User avatar
Hove
Posts: 1205
Joined: Sun Oct 21, 2012 6:55 pm
Location: Cotswolds, UK
Contact: Website

Python + espeak

Sun Oct 13, 2013 2:19 pm

I thought I'd have a play with espeak the other day; I downloaded espeak, espeak-gui and python-espeak.

command line works well
gui works well
python script worked within IDLE

Code: Select all

#!/usr/bin/env python

from espeak import espeak
print espeak.__file__
espeak.synth("Good morning, sir")
But run from the command line as "python ./speech.py" I get this:

Code: Select all

pi@generalpi ~/Downloads $ python ./speech.py
/usr/lib/pymodules/python2.7/espeak/espeak.pyc
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
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
pi@generalpi ~/Downloads $ 
Any thoughts, suggestions or explanations, fixes most welcome.

Thanks
www.pistuffing.co.uk - Raspberry Pi and other stuffing!

RegW
Posts: 2
Joined: Sun Nov 17, 2013 6:44 pm

Re: Python + espeak

Tue Dec 17, 2013 12:01 pm

Perhaps this is a bit late for a reply but it might help someone else.

I have been using espeak with pyttsx. Even though it works and I hear speech, I always get a load of errors just like yours which are listed by espeak as it initialises during the first utterance. It seems to be searching of an acceptable output device, and outputting a line out on stderr for each it fails to find. I would bet if you started your IDE from the command line you would also see them listed then.

As these are coming from down in a C library, you can't just stop it by re-assigning sys.stderr within python. However, you can briefly redirect the stderr for the whole process using the stdchannel_redirected function given by Marc Abramowitz on his blog.

Here is how I use it:

Code: Select all

engine = pyttsx.init()
engine.setProperty("voice","english_rp")
engine.setProperty("rate",180)
engine.say("Starting up")
with stdchannel_redirected(sys.stderr, os.devnull):
        engine.runAndWait()
print >> sys.stderr, "stderr back to normal"
Hope that helps.

P.S. The python-espeak module doesn't seem to work for me, but it's probably something I've been doing wrong. Pyttsx takes a bit of installing on the Pi - something like this:

Code: Select all

sudo apt-get install espeak python-setuptools
sudo easy_install pip
sudo pip install pyttsx
P.P.S.
Now to workout why espeak misses out (at least) the first two words of every utterance, and slows down on long pieces of text.

Return to “Python”