Converting text to mp3

Linux for blind general discussion blinux-list at
Wed Jan 26 17:46:13 UTC 2022

I can only find something called gtts, which takes your written text or 
a text file, pipes it to the Google TTS API and sends an mp3 file to 
standard output or to the mp3 file you name. So I was able to run in a 

gtts-cli "This is a test of the system." | play -q -t mp3 -

and I heard it speak using one of Google's female voices ... it sounded 
like the assistant actually, which means that I should be able to change 
the voice to any of the other assistant voices, though I haven't figured 
out yet how to do that. I can see that it is also possible to run 
something like

gtts-cli -f book.txt -o audiobook.mp3

and your mp3 file would be stored on disk instead of just being played 
from the standard output of gtts piped into sox. That said, I don't know 
what the maximum length of the file to be spoken can be, since the 
script is using Google's API, so it may need to be broken up.

Other than this, I see nothing else that will directly take text input 
and produce mp3 output, but most speech synthesizers can take text from 
a file, from standard input or from a command line and speak via either 
standard output or a wav file. You could take that and pipe it either 
through sox or lame to get an mp3 file. A good example using espeak would be

espeak-ng -f book.txt --stdout | lame -q 9 book.mp3

Check manuals or help text for the specific synthesizer you want to use, 
since the command lines to control them vary widely. Hope this helps.


More information about the Blinux-list mailing list