I'd like to convert an text file to an mp3 file using espeak. Is it possible to do this? I'm trying to use espeak to create a song synthesis shell script that can convert text to a song.
-
1I think this page explains how to generate mp3 files (at least partially): https://npmjs.org/package/espeak – Anderson Green Aug 21 '12 at 21:50
-
And here's an explanation of how to do this using a shell script: http://eceppda.github.com/nerdterm/2011/11/23/ESPEAK.html – Anderson Green Aug 21 '12 at 21:54
-
Also, it's possible to do pitch shifting using a program called rubberband. – Anderson Green Aug 21 '12 at 22:12
4 Answers
There's two ways of doing this; if you just want a wav
file, see the first example, and for an mp3
conversion see the second.
1) Feed espeak
your text file using the -f
option, then use the --stdout
option and redirect its data stream to file to create a valid wav
file that plays correctly in any audio player.
espeak -f mytext --stdout > myaudio
Result checked with the file
command (file myaudio
):
myaudio: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 22050 Hz
2) If you want an mp3 conversion you will have to use a program to convert your file (or simply save it in audacity
and export it as mp3). I have used ffmpeg
(the git version), but you can use any program and just change the options:
espeak -f myfile --stdout | ffmpeg -i - -ar 44100 -ac 2 -ab 192k -f mp3 final.mp3
Result checked with file final.mp3
:
final.mp3: Audio file with ID3 version 2.4.0, contains: MPEG ADTS, layer III, v1, 192 kbps, 44.1 kHz, Stereo

- 5,312
-
1This works but the quality of espeak is hideous. Can barely make out what it is saying. Isn't there a way to use Amazon Poly or something .... understandable? – Joshua Robison Nov 07 '21 at 02:41
-
I actually wrote a script achieving this... and it ended up working quite well.
https://github.com/divVerent/ecantorix
Example: https://github.com/downloads/divVerent/ecantorix/sarastro.ogg
-
1I can't tell if that's the best or the creepiest thing I've heard today. Good work. – Oli Oct 24 '12 at 13:13
-
1This is not a direct reply to the question, but it is so crazy that it deserves an upvote anyway! – mivk May 15 '13 at 19:35
espeak now has a -w option which outputs to wav
(It still would need to be converted to mp3 afterwards.)
espeak -f foo.txt -w foo.wav

- 179
The --stdout
option to espeak will tell it to write the audio data to stdout instead of putting it through the audio device. From there you can pipe it into e.g. ffmpeg for conversion to the proper format.

- 4,332
-
-
1I haven't found any; I just understand how programs work. – Ignacio Vazquez-Abrams Aug 21 '12 at 22:13
-
This question is perhaps relevant as well: http://stackoverflow.com/questions/2762164/how-to-make-computer-sing – Anderson Green Aug 21 '12 at 22:35