Raspberry pi如何使用子进程和espeak

时间:2016-08-06 13:39:48

标签: python raspberry-pi subprocess espeak

我现在正在寻找如何使用espeak宣布一个句子的方法。当我在终端时,当我输入

espeak -s 5 "where are you" --stdout | aplay

它出来了

pi@raspberrypi ~ $ espeak -s 5 "where are you" --stdout | aplay
Playing WAVE 'stdin' : Signed 16 bit Little Endian, Rate 22050 Hz, Mono

然后,如果我删除了--stdout | aplay,它就变成了:

pi@raspberrypi ~ $ espeak -s 5 "where are you"
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

然后,我意识到为了在python文件中运行它,我必须使用subprocess.call()函数

import subprocess
subprocess.call(["espeak", "-s 5 -ven", "where are you"])

上面的代码没问题。但是当我使用下面的代码时,就像地狱一样松散,并且我的屏幕上会不断出现许多奇怪的角色。

import subprocess
subprocess.call(["espeak", "-s 5 -ven", "where are you", "--stdout", "|", "aplay"])

第一个问题是--stdout | aplay实际意味着什么? 然后,如何将它放在subprocess.call中,这样它会起作用吗?原因是没有--stdout | aplay,当句子更长时,声音似乎滞后/断断续续。

0 个答案:

没有答案