3

I'm trying to call

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

through 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 idea how to implement this? Thx

GWorking
  • 3,166
  • 3
  • 34
  • 68
  • Yes, it works like a charm, BIG THANKS :) *If you answer as a question I'll marked that as the solution – GWorking Jan 12 '15 at 23:46

1 Answers1

4

Your example is the equivalent of typing this in the shell:

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

Which is obviously wrong. Each list entry is one argument (argv entry) passed to the executable, no escaping/quoting needed on your side. So 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 should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.

Martin Tournoij
  • 23,567
  • 24
  • 90
  • 127