Subprocess.call和--stdout

时间:2016-08-07 04:35:52

标签: 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在这里意味着什么吗?为什么它会引起上述错误?

1 个答案:

答案 0 :(得分:1)

来自espeak documentation

  

- stdout

     

在生成时将语音输出写入stdout,而不是说出来。   数据以WAV文件头开头   表示采样率和数据格式。长度字段是   设置为零,因为标题时数据的长度是未知的   生产。

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

  

您是否安装了alsa软件包(输入'alsa'和tab键   两次,你应该看到一些以alsa开头的命令..)?如果它   未安装,请使用

执行此操作
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方法本身的参数。 只需删除它。