How to use python Popen with espeak and aplay

I am trying to call

espeak -ves -s130 'HEY' --stdout | aplay -D 'sysdefault'

      

via subprocess.Popen, with

espeak_process = Popen(["espeak", "-ves -s100 'HEY' --stdout"], stdout=subprocess.PIPE)
aplay_process = Popen(["aplay", "-D 'sysdefault'"], stdin=espeak_process.stdout, stdout=subprocess.PIPE)

      

But it doesn't work

ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM  'sysdefault'
aplay: main:682: audio open error: No such file or directory

      

Any ideas how to implement this? thank

+3


source to share


1 answer


Your example is equivalent to writing this in the shell:

$ espeak '-ves -s100 \'HEY\' --stdout'
$ aplay '-D \'sysdefault\''

      

This is obviously wrong. Each list entry is one argument (argv entry) passed to the executable, without the need for escaping / quoting on your side. Therefore, you want to use:



["aplay", "-D", "sysdefault"]
["espeak", "-ves", "-s100", "HEY", "--stdout"],

      

Also see the documentation (emphasis mine):

args is required for all calls and must be a string or sequence of program arguments. Providing a sequence of arguments is generally preferred as it allows the module to take care of any required argument escaping and quoting (for example, allowing spaces in filenames) . If you pass a single string, either the wrapper must be True (see below), or the string must simply specify the program to run without supplying any arguments.

+4


source







All Articles