How to use python Popen with a espeak and aplay

不打扰是莪最后的温柔 提交于 2019-12-05 20:20:20

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!