python - Subprocess.call 和 --stdout

标签 python raspberry-pi subprocess stdout espeak

subprocess.call(["espeak", "-s 5 -ven", "where are you", "--stdout", 'shell=True', "aplay"])

此输出将只是大量特殊字符的输出,而不是来自 espeak 的音频。当我输入这个时:

subprocess.call(["espeak", "-s 5 -ven", "where are you", 'shell=True', "aplay"])

然后就可以听到声音了,但是有时会出现说话慢的问题,同时输出如下信息:

ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.front
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround40
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround41
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround50
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround51
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.surround71
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.iec958
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.hdmi
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.modem
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm.c:2217:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.phoneline
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started

有人可以解释 --stdout 在这里的意思吗?为什么会导致上述错误?

最佳答案

来自 espeak documentation :

--stdout

Writes the speech output to stdout as it is produced, rather than speaking it. The data starts with a WAV file header which indicates the sample rate and format of the data. The length field is set to zero because the length of the data is unknown when the header is produced.

对于jack server is not running or cannot be started错误检查this link解决方案:

Do you have installed the alsa package (type 'alsa' and the tab key twice, you should see some commands beginning with alsa..)? If it isn't installed, do that with

sudo apt-get install alsa-tools alsa-utils

无论如何,这个错误不应该阻止 espeak 工作。您可以通过将 stderr 重定向到 /dev/null 来删除它,如下所示:

FNULL = open(os.devnull, 'w')
retcode = subprocess.call(["espeak", "-s 5", "-ven", "where are you", "aplay"], stdout=FNULL, stderr=subprocess.STDOUT)

另请注意,您使用 shell=True 作为 espeak 的参数之一,它实际上应该是 call 的参数方法本身。 只需将其删除即可。

关于python - Subprocess.call 和 --stdout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38810897/

相关文章:

python - 打开一个没有焦点的 pyglet 窗口

python - 在没有管理员权限的情况下安装 rpy2

python - 将缺失值附加到 CSV 文件

python - 使用 scrapy 爬虫进行虚假地理定位

raspberry-pi - 无法找到 libv41-dev 软件包进行安装

python - 导入错误 : No module named adafruit_motor

Python 子进程 block

python - 链接多个combine_first()

Php 序列号 : No stty available -- cant seem to get it working

python - 在 Python subprocess.Popen() 中处理 Shell 重定向