我在 Raspberry Pi 3B 上使用 Lubuntu 20.04。
我正在尝试使用 gtts-cli(文本到语音程序)通过以下方式直接生成音频:
gtts-cli "Almost no modern computer function works properly" | mpg321 -
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
tcgetattr(): Inappropriate ioctl for device
Playing MPEG stream from - ...
MPEG 2.0 layer III, 32 kbit/s, 24000 Hz mono
[0:03] Decoding of - finished.
Segmentation fault
有时它可以工作,有时则不行。当它不工作时,我会听到咔嗒声、刺耳的声音或刺耳的声音,然后是音频的最后一部分。这让我想到,有时 mpg321 会错过音频的第一部分,或者以某种方式损坏它。即使它正确地重现了所有的音频,也会出现分段错误。
我做了一些调查。首先,为了排除 gtts-cli 是问题的根源,我录制了 mp3 输出并将其发送到 mpg321。例如
gtts-cli "It is enough to drive you mad!" -o test.mp3
cat test.mp3 | mpg321 -
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
tcgetattr(): Inappropriate ioctl for device
Playing MPEG stream from - ...
MPEG 2.0 layer III, 32 kbit/s, 24000 Hz mono
[0:03] Decoding of - finished.
Segmentation fault
我遇到了同样的问题。有时它可以工作,有时它会错过所有内容,或者错过音频的开头。而且总是会出现分段错误。
我检查了问题是否是由于直接使用文件从 stdin 向 mpg321 输入造成的:
mpg321 test.mp3
High Performance MPEG 1.0/2.0/2.5 Audio Player for Layer 1, 2, and 3.
Version 0.3.2-1 (2012/03/25). Written and copyrights by Joe Drew,
now maintained by Nanakos Chrysostomos and others.
Uses code from various people. See 'README' for more!
THIS SOFTWARE COMES WITH ABSOLUTELY NO WARRANTY! USE AT YOUR OWN RISK!
Playing MPEG stream from test.mp3 ...
MPEG 2.0 layer III, 32 kbit/s, 24000 Hz mono
开始时仍然会错过一些音频,但不会出现分段错误。
我的音频进入 Respeaker USB 输出。为了排除问题出在驱动程序或 mpg321 下游音频生产中的可能性,我尝试了:
aplay temp.wav
每次播放都完美且一致。
然后我安装并尝试了 mpg123(而不是 mpg321)。结果类似,但我认为比 mpg321 稍差一些。
我尝试重新安装 mpg321 - 没有变化。
哪里出了问题?更重要的是,我该如何解决它?
答案1
我在从 python 脚本调用 mpg321 时遇到了类似的问题,该脚本是在重启时通过 crontab 从 bash 脚本启动的。我收到一个模糊的错误:tcgetattr():设备的 ioctl 不合适。在浏览了无数个线程并尝试了所有我能尝试的方法后,我尝试改为使用 omxplayer,似乎解决了这个问题。我能说的最好的是,这是从 crontab 启动时出现的某种权限问题,因为我可以从终端会话中毫无问题地运行它。