Subprocess.call 和 --stdout
Subprocess.call and --stdout
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 在这里是什么意思?为什么会导致上述错误?
--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
方法本身的参数。
删除它即可。
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 在这里是什么意思?为什么会导致上述错误?
--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
方法本身的参数。
删除它即可。