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
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.
来源:https://stackoverflow.com/questions/27912586/how-to-use-python-popen-with-a-espeak-and-aplay