如何通过espeak和aplay使用python Popen
作者:互联网
我正在尝试打电话
espeak -ves -s130 'HEY' --stdout | aplay -D 'sysdefault'
通过subprocess.Popen,
espeak_process = Popen(["espeak", "-ves -s100 'HEY' --stdout"], stdout=subprocess.PIPE)
aplay_process = Popen(["aplay", "-D 'sysdefault'"], stdin=espeak_process.stdout, stdout=subprocess.PIPE)
但这不起作用
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM 'sysdefault'
aplay: main:682: audio open error: No such file or directory
任何想法如何实现这一点?
谢谢
解决方法:
您的示例等效于在shell中键入以下内容:
$espeak '-ves -s100 \'HEY\' --stdout'
$aplay '-D \'sysdefault\''
这显然是错误的.每个列表条目都是传递给可执行文件的一个参数(argv条目),无需在您身边进行转义/引用.所以你要使用:
["aplay", "-D", "sysdefault"]
["espeak", "-ves", "-s100", "HEY", "--stdout"],
另请参见the documentation(重点是我的):
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.
标签:asynchronous,popen,espeak,python 来源: https://codeday.me/bug/20191028/1955016.html