pythonraspberry-pisubprocessstdoutespeak

Subprocess.call and --stdout


subprocess.call(["espeak", "-s 5 -ven", "where are you", "--stdout", 'shell=True', "aplay"])

The output of this will just be a massive output of special characters, and not the audio from the espeak. When i type this:

subprocess.call(["espeak", "-s 5 -ven", "where are you", 'shell=True', "aplay"])

then the audio is heard, but there are some problems with the speech being slow sometimes, together with output of messages below:

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

Can someone explain what --stdout means here? And why is it causing the error as mentioned?


Solution

  • From espeak documentation:

    --stdout

    Writes the speech output to stdout as it is produced, rather than speaking it. The data starts with a WAV file header which indicates the sample rate and format of the data. The length field is set to zero because the length of the data is unknown when the header is produced.

    For jack server is not running or cannot be started error check this link for solution:

    Do you have installed the alsa package (type 'alsa' and the tab key twice, you should see some commands beginning with alsa..)? If it isn't installed, do that with

    sudo apt-get install alsa-tools alsa-utils
    

    Anyway this error shouldn't prevent espeak from working. You can remove it by redirecting stderr to /dev/null as follows:

    FNULL = open(os.devnull, 'w')
    retcode = subprocess.call(["espeak", "-s 5", "-ven", "where are you", "aplay"], stdout=FNULL, stderr=subprocess.STDOUT)
    

    Also please note that you're using shell=True as one of the arguments to espeak, which should be actually argument of call method itself. Just remove it.