2

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

iChux
  • 2,266
  • 22
  • 37
  • What exactly is the question? Do you want ffmpeg to convert `details.wav` to mp3? Or do you want ffmpeg to read text from the text file and create an mp3 output? Both are possible. – llogan Oct 30 '13 at 19:01
  • @LordNeckbeard, the **-w** will make it output a .wav, specified as **details.wav**. The output I showed was to let people know that I'm able to output to .wav. The closest I got to output espeak [link](http://askubuntu.com/questions/178736/generate-mp3-file-from-espeak) to mp3 format is: **espeak -f myfile --stdout | ffmpeg -i - -ar 44100 -ac 2 -ab 192k -f mp3 final.mp3** When I tried it I got many errors. **The main task is that I want to be able to output mp3 file from espeak on Ubuntu**. Thanks. – iChux Oct 31 '13 at 06:56
  • You should show your ffmpeg command and complete console output (adding them to your question) if you want to know why that didn't work for you. – llogan Oct 31 '13 at 17:37
  • @LordNeckbeard, thanks for offering to help. The output is lengthy, but this is it: http://pastebin.com/wJaifig0. – iChux Nov 01 '13 at 08:32
  • That's the [fake "ffmpeg"](http://stackoverflow.com/a/9477756/1109017) from libav. You [probably needed the `libavcodec-extra-5*`](http://superuser.com/a/653587/110524) (52 or 53) package to enable mp3 encoding in ffmpeg. Note that official support for 11.04 has ended on 2012-10-28. – llogan Nov 01 '13 at 18:03
  • @LordNeckbeard, I tried your method, thanks for pointing it out. I got the following errors as displayed at [link](http://pastebin.com/xcWWGcEz), largely because I don't have the final rights to do the installation. – iChux Nov 01 '13 at 18:46
  • Maybe interference from packages from a PPA. I do not think it matters much since you found a solution with `lame`. – llogan Nov 01 '13 at 19:33
  • I think [lame](http://lame.sourceforge.net/) and [sox](http://sox.sourceforge.net/) are best option to work with audio, give them a try. – Álvaro Nov 05 '13 at 08:41
  • @Álvaro, thanks, I've already tried out LAME. In general, I just want a good text to speech tool on Linux, if any. – iChux Nov 05 '13 at 08:54

1 Answers1

3

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.

iChux
  • 2,266
  • 22
  • 37