How can I convert a text file to audio (mp3) using ffmpeg on Ubuntu 11.04?

2.4k Views Asked by At

I would like to output .mp3 file from a text file on Ubuntu 11.04, using ffmpeg. Please, how do I do this? The best I could output is a .wav file. I intend to be able to use it in a Python file.

My output method for .wav is espeak -s 155 -a 200 -f details.txt -w details.wav

1

There are 1 best solutions below

0
iChux On

Well, I've found a way around it. I wrapped it in a Python script, as shown below:

from subprocess import Popen
from os import remove


def tts(text_file, wav_file, mp3_file):
    Popen(["espeak", "-v", "en-uk", "-f", text_file, "-w", wav_file]).communicate()
    Popen(["lame", "--ta", "nwaomachux", "--tt", "Latest Update", wav_file, mp3_file]).communicate()
    remove(wav_file)
    remove(text_file)


if __name__ == '__main__':
    wav_ = '/home/nwaomachux/Dropbox/news_update.wav'
    mp3_ = '/home/nwaomachux/Dropbox/news_update.mp3'
    txt_ = '/home/nwaomachux/Dropbox/news_upd.txt'

    tts(txt_, wav_, mp3_)

Please I'm open to suggestions and corrections. What I was able to achieve here is to output to .mp3 format without having to go through the ffmpeg I earlier wanted.