如何通过espeak和aplay使用python Popen [英] How to use python Popen with a espeak and aplay

查看:222
本文介绍了如何通过espeak和aplay使用python Popen的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试致电

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

通过subprocess.Popen,带有

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)

但这不起作用

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

推荐答案

您的示例等效于在shell中键入以下内容:

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

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

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

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,并且应为字符串或程序参数序列. 通常最好提供一个参数序列,因为它允许模块处理任何必需的参数转义和引用(例如,允许在文件名中留空格).如果传递单个字符串,则外壳程序必须为True(请参见下文),否则该字符串必须简单地命名要执行的程序而无需指定任何参数.

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.

这篇关于如何通过espeak和aplay使用python Popen的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆