ATRedline
Posts: 6
Joined: Wed Aug 21, 2019 3:55 pm

espeak doesnt work

Wed Aug 21, 2019 4:13 pm

I need espeak for my project. I made fresh installation of oficial raspbian, install updates, and next i made next steps:
sudo apt-get install espeak python-espeak python-pyaudio
pip install pyttsx3

and then, if i run following code on python:

Code: Select all

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices')

engine.say('Hello!')
engine.runAndWait()
i've get multiple errors:
Image

then i tried to use espeak in terminal, and for:

Code: Select all

 espeak "Hello world"
i've get the same errors as in the python.
And when i tried that way:

Code: Select all

'espeak "Hello World"  2>/dev/null
There is no errors, but it dont work too - just silense (i tried force 3.5 output and HDMI output - still silence, but sound in web browser works fine)

What i did wrong? How can i fix espeak?

hippy
Posts: 6237
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: espeak doesnt work

Wed Aug 21, 2019 10:26 pm

This seems to all come down to something wrong with ALSA which espeak uses and possibly your pyttsx3. It was broken in Stretch, and remains broken in Buster.

I experience the same 'doesn't work' as you with -

espeak "Hello world"
espeak "Hello World" 2>/dev/null

The only ways I have managed to get espeak working reliably for me is with -

espeak "Hello World" --stdout | aplay

espeak "Hello World" --stdout > file.wav
aplay file.wav

But, using the first, it has now started to sometimes drop the start of what is being spoken.

There are plenty of reports of problems but I am not sure what is being done about those, who would be expected to fix it.

Rolling back the kernel to an earlier version seems to be the only fix verified by others. I don't particularly want to do that myself so cannot confirm if it fixes things or not.

hippy
Posts: 6237
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: espeak doesnt work

Wed Aug 21, 2019 10:39 pm

ATRedline wrote:
Wed Aug 21, 2019 4:13 pm

Code: Select all

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices')

engine.say('Hello!')
engine.runAndWait()
If you are simply after getting your Python code to speak you could forego the above and just use -

Code: Select all

import os
os.popen( 'espeak "Hello!" --stdout | aplay 2>/dev/null' )

Code: Select all

import os
def Say(text):
  os.popen( 'espeak "'+text+'" --stdout | aplay 2>/dev/null' )
Say("Hello")
Works for me on a Pi 3B (non-plus) running Buster.

ATRedline
Posts: 6
Joined: Wed Aug 21, 2019 3:55 pm

Re: espeak doesnt work

Wed Aug 21, 2019 10:44 pm

hippy wrote:
Wed Aug 21, 2019 10:26 pm
This seems to all come down to something wrong with ALSA which espeak uses and possibly your pyttsx3. It was broken in Stretch, and remains broken in Buster.
Hi! Thanks for your answer. I saw other threads with that issue too late. In this thread i finded half of solution:
https://www.raspberrypi.org/forums/view ... 6&t=241814
With "PA_ALSA_PLUGHW=1" in environment variables "espeak "Hello" " works, but with noises and still with errors. Also i finded solution how to run espeak with --stdoutput.
I spent half of day to make it works, listened to it, and now i dissapointed in it - voice is too ugly. I already finded RHVoise, and it very good solution for my purposes.
So, thread can be closed... I'm sorry i hurried with it

ATRedline
Posts: 6
Joined: Wed Aug 21, 2019 3:55 pm

Re: espeak doesnt work

Wed Aug 21, 2019 10:47 pm

hippy wrote:
Wed Aug 21, 2019 10:39 pm
If you are simply after getting your Python code to speak you could forego the above and just use -
Thatnks man, already did this:

Code: Select all

def espeak(text):
    lang = ''
    rl = re.compile((r'^[а-яё].+$'), re.I)
    if rl.search(text): lang = '-vru '
    command = 'espeak '+lang+'"'+text+'" --stdout |aplay'
    print(command)
    os.system(command)

def rhvoice(text):
    temp = '80'
    tembr = '80'
    command = 'echo "' + text + '" | RHVoice-test  -t ' + tembr + ' -r ' + temp + ' -v 150 -p aleksandr+alan'
    os.system(command)
espeak sounds ugly(

hippy
Posts: 6237
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: espeak doesnt work

Thu Aug 22, 2019 4:25 pm

ATRedline wrote:
Wed Aug 21, 2019 10:47 pm
espeak sounds ugly(
It's definitely an acquired taste. I like picoTTS on Android but found the packaged version for Pi wasn't that great. Espeak is therefore what I have stuck with but I am always willing to give other things a try, hoping I will one day find something I like.

Do you have instructions for getting RHVoice working on a Pi ? I tried to build it, and portaudio, but I think I am missing something somewhere -

Code: Select all

sudo apt-get install scons

cd ~
git clone  https://git.assembla.com/portaudio.git
cd portaudio
./configure
make clean
make
sudo make install
sudo ldconfig

cd~
git clone https://github.com/Olga-Yakovleva/RHVoice.git
cd RHVoice
scons
sudo scons install
sudo ldconfig

echo "Hello World" | RHVoice-test
That all worked fine but "RHVoice-test: command not found", possibly because it can't find portaudio or aother dependency ...

Code: Select all

pi@Pi3B:~/RHVoice $ sudo scons install
scons: Reading SConscript files ...
Mkdir("build/linux")
Checking whether the C compiler works... (cached) yes
Checking whether the C++ compiler works... (cached) yes
Checking for pkg-config... (cached) yes
Checking for libpulse-simple... (cached) no
Checking for ao... (cached) no
Checking for portaudio-2.0... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
scons: `install' is up to date.
scons: done building targets.
pi@Pi3B:~/RHVoice $

ATRedline
Posts: 6
Joined: Wed Aug 21, 2019 3:55 pm

Re: espeak doesnt work

Thu Aug 22, 2019 8:30 pm

hippy wrote:
Thu Aug 22, 2019 4:25 pm
Espeak is therefore what I have stuck
Espeak is not that bad in English, but i need Russian syntesizer - with Russian voise espeak is terrible. And also i love espeak for its speed. RHVoise is slower than Espeak. RHVoise is slower than Espeak, but faster than gTTS. gTTS, by the way, not bad, but it needs connection, and it doesnt have selection of voises and parameters, unlike RHVoice
hippy wrote:
Thu Aug 22, 2019 4:25 pm
Do you have instructions for getting RHVoice working on a Pi ?
That all worked fine but "RHVoice-test: command not found", possibly because it can't find portaudio or aother dependency ...
I made next steps:

Code: Select all

sudo apt-get install scons g++ pkg-config git libpulse-dev speech-dispatcher

git clone https://github.com/Olga-Yakovleva/RHVoice.git
cd RHVoice

scons
sudo scons install (sudo scons --clean install for remove)
sudo ldconfig

sudo cp -a /usr/local/bin/sd_rhvoice /usr/lib/speech-dispatcher-modules

sudo nano /etc/speech-dispatcher/modules/rhvoice.conf:
_______________________________________________________

RHVoiceDataPath "/usr/local/share/RHVoice"
RHVoiceConfigPath "/usr/local/etc/RHVoice/"
RHVoicePunctuationMode 
#RHVoicePunctuationList "@+_"
RHVoiceDefaultVoice "Aleksandr"
RHVoiceDefaultVariant "Pseudo-English"
Debug
_______________________________________________________

sudo nano /etc/speech-dispatcher/speechd.conf:
_______________________________________________________
in the end:
#AddModule "rhvoice" "sd_rhvoice" "rhvoice.conf"
_______________________________________________________
RHVoise-test is work, RHVoise-client: "command not found", so, i using by that way:

Code: Select all

echo «Hello World!» | RHVoice-test  -t 50 -r 70 -v 150 -p alan

english voices:  alan, clb

speech rate: -r = 50--200
speech pitch: -t = 50--200
speech volume: -v = 100 ->
default = 100. 
and also, symbols like ' is not accepted.

hippy
Posts: 6237
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: espeak doesnt work

Thu Aug 22, 2019 10:40 pm

Thanks for details. Turned out I needed a reboot to gel libpulse-dev to be seen when building RHVoice. After that libpulse-simple and portaudio-2.0 appear as "(cached) yes" with scons.

It seems to be working though all those ALSA errors are appearing. With 2>/dev/null they can be hidden and it does actually speak.

It is certainly less robotic than espeak. I'll update my own speech programs and see how I get on with RHVoice.

ATRedline
Posts: 6
Joined: Wed Aug 21, 2019 3:55 pm

Re: espeak doesnt work

Thu Aug 22, 2019 11:36 pm

hippy wrote:
Thu Aug 22, 2019 10:40 pm
It seems to be working though all those ALSA errors are appearing. With 2>/dev/null they can be hidden and it does actually speak.
Are you getting ALSA errors under RHVoice? I'm not

hippy
Posts: 6237
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: espeak doesnt work

Mon Aug 26, 2019 3:04 pm

ATRedline wrote:
Thu Aug 22, 2019 11:36 pm
hippy wrote:
Thu Aug 22, 2019 10:40 pm
It seems to be working though all those ALSA errors are appearing. With 2>/dev/null they can be hidden and it does actually speak.
Are you getting ALSA errors under RHVoice? I'm not
It produces audio output but churns out a lot of errors -

Code: Select all

pi@Pi3B:~ $ echo "Hello" | RHVoice-test  -t 50 -r 70 -v 150 -p alan
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 924
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 924
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 934
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 934
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 934
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa
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
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
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib conf.c:5014:(snd_config_expand) Unknown parameters {AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
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
default Engine is default
pi@Pi3B:~ $
Worse, I have lost audio routing as per the following link, apparently I need to uninstall PulseAudio -

https://www.raspberrypi.org/forums/view ... hp?t=24943

And that seems to have broken the RHVoice installation, and won't recompile because scons now throws errors. Decided to start-over from scratch and built that with portaudio, no pulseaudio.

That's now worse than earlier, more errors and no audio output -

Code: Select all

pi@Pi3B:~ $ echo "Hello" | RHVoice-test  -t 50 -r 70 -v 150 -p alan
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 924
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 924
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround21
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 934
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 934
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 934
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa
ALSA lib confmisc.c:1281:(snd_func_refer) Unable to find definition 'defaults.bluealsa.device'
ALSA lib conf.c:4568:(_snd_config_evaluate) function snd_func_refer returned error: No such file or directory
ALSA lib conf.c:5036:(snd_config_expand) Args evaluate error: No such file or directory
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM bluealsa
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
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
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pcm_oss.c:377:(_snd_pcm_oss_open) Unknown field port
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Connection refused

ALSA lib pcm_a52.c:823:(_snd_pcm_a52_open) a52 is only for playback
ALSA lib conf.c:5014:(snd_config_expand) Unknown parameters {AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
ALSA lib pcm.c:2565:(snd_pcm_open_noupdate) Unknown PCM iec958:{AES0 0x6 AES1 0x82 AES2 0x0 AES3 0x2  CARD 0}
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
ALSA lib pcm_usb_stream.c:486:(_snd_pcm_usb_stream_open) Invalid type for card
Expression 'alsa_snd_pcm_hw_params_set_period_size_near( pcm, hwParams, &alsaPeriodFrames, &dir )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 924
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
default Engine is default
Expression 'paInvalidSampleRate' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2048
Expression 'PaAlsaStreamComponent_InitialConfigure( &self->playback, outParams, self->primeBuffers, hwParamsPlayback, &realSr )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2722
Expression 'PaAlsaStream_Configure( stream, inputParameters, outputParameters, sampleRate, framesPerBuffer, &inputLatency, &outputLatency, &hostBufferSizeMode )' failed in 'src/hostapi/alsa/pa_linux_alsa.c', line: 2843
pi@Pi3B:~ $
But an improvement with using espeak "Hello World" with no --stdout. Lots of errors as per above, but it's now speaking , though losing the start; "orld".

At least espeak "Hello World" --stdout | aplay still works so I'll stick with using that for now.

The bottom-line take home remains; ALSA is a badly broken mess, and has been for some time.

amcdonley
Posts: 182
Joined: Mon Jan 26, 2015 5:56 pm
Location: Florida, USA

Re: espeak doesnt work

Mon Sep 23, 2019 1:27 am

After updating my Raspbian Stretch:
```
Linux Carl 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l GNU/Linux
```

espeak stopped working completely for me.

I got it to speak again by adding the following to my /home/pi/.bashrc
```
PA_ALSA_PLUGHW=1
export PA_ALSA_PLUGHW
```
(and rescanning it - `source .bashrc` )

but there is distortion at all volume levels for some reason.

Return to “Troubleshooting”