如何将python Popen与espeak和aplay一起使用

2024-06-28 19:53:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我在打电话

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

通过子流程.Popen,与

^{pr2}$

但它不起作用

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

你知道怎么实施吗? 泰铢


Tags: libstdout流程openalsapcmpopenespeak
1条回答
网友
1楼 · 发布于 2024-06-28 19:53:29

您的示例相当于在shell中键入以下内容:

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

这显然是错误的。每个列表条目都是传递给可执行文件的一个参数(argv条目),您不需要转义/引用。所以你要使用:

^{pr2}$

另请参见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.

相关问题 更多 >