I am using Lubuntu 20.04 on a Raspberry Pi 3B.
I am trying to use gtts-cli (text to speech program) to generate audio directly by:
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
Sometimes it works, and sometimes it doesn't. When it does not work, I hear either a click, a grating sound, or a grating sound followed by the last part of the audio. It makes me think that sometimes mpg321 misses the first part of the audio, or corrupt it in some way. Even when it reproduces all the audio correctly, there is a SEGMENTATION FAULT.
I did some investigation. Firstly, to eliminate gtts-cli as the source of the problem, I recorded mp3 output from it and sent that to mpg321. e.g
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
I get the same effect. Sometimes it works and sometimes it misses all, or the start of the audio. There is also always a segmentation fault.
I checked if the problem is due to feeding input to mpg321 from stdin, by using the file directly:
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
That still misses some audio at the start, but does NOT give a segmentation fault.
My audio goes to Respeaker USB output. To eliminate the possibility of the problem being in the driver or audio production downstream of mpg321, I tried:
aplay temp.wav
That plays perfectly and consistently every time.
I then installed and tried mpg123 (instead of mpg321). The results were similar, but I think slightly worse than mpg321.
I tried re-installing mpg321 - no change.
What is wrong, and more importantly how can I fix it?