text2Mp3

Technology

Here is a way to make mp3 out of news articles. It allows me to reduce browsing time and listen to news while I do something else, such as being in the lab. This looks like a lot, but once you get the hang of it, it is very fast.

1. Safari

Open the news articles of interest. It there are many command-click to open them in separate tabs.

Simplify formatting and get rid of commercials by entering reader mode Cmd-Shift-R.

Select all text, copy and paste to empty txt file. This can be done faster using Launchbar, by selecting text, invoking the LaunchBar shortcut holding space (to pass selection to LaunchBar), and tabing to “new txt document”.

Save the text document with a name starting in “en” or “gr” depending on language.

2. Folder setup

I have the following folders. They take the text files (input) and hold all mp3 (output)

~/Automation/Text2Speech/gr/
~/Automation/Text2Speech/en/
~/Automation/mp3/

You can manually copy the txt files there, or select the files of one language, pass them to LaunchBar by holding space while invoking it and then tabbing to “mp3” to quickly select the folder to move them to.

3. bashrc function

I add the following function to my .bashrc. It could be run manually but that gets old soon. It uses the say command, already available on the Mac terminal. It also uses FFmpeg which needs to be installed e.g. brew install ffmpeg.

function t2s {
    cd ~/Automation/Text2Speech/gr/

    for i in $(ls | grep txt | perl -pe 's/.txt//'); do say -v Melina -f $i.txt -o $i.aiff; done

    for i in $(ls | grep aiff | perl -pe 's/.aiff//'); do ffmpeg -i $i.aiff $i.mp3; done

    rm *txt

    rm *aiff

    mv *.mp3 ~/Automation/mp3/

    cd ~/Automation/Text2Speech/en/

    for i in $(ls | grep txt | perl -pe 's/.txt//'); do say -v Daniel -f $i.txt -o $i.aiff; done

    for i in $(ls | grep aiff | perl -pe 's/.aiff//'); do ffmpeg -i $i.aiff $i.mp3; done

    rm *txt

    rm *aiff

    mv *.mp3 ~/Automation/mp3/
}

Here is the explanation for the function:

Go to the gr folder.

Run a loop for each txt file, which keeps only the filename (no externsion) and runs the say command with the Melina voice (Greek) on each file. Make an aiff file with the same name.

Run a loop on each aiff file, which keeps only the filename (no extension) and run ffmpeg to make an mp3 file out of the aiff file.

Delete the intermediate txt and aiff files.

Move the mp3 files into the mp3 folder.

Repeat in the en folder with the Daniel voice (British English).

If you like other voices/languages, check available voices with

say -v '?'

4. Move mp3 files to phone

My preferred way is to upload to my Overcast account. However this needs a paid subscription, but the speed and simplicity makes it worth it. It is also good to support independent developers of software I use every day.

It can be done for free in the ios podcast player Downcast. You first put your files to iCloud (or the mp3 folder can already be in iCloud), then download them in files app on the iOS device, and then select the import option in Downcast. This gets annoying quite soon, especially if you do this a lot, as there are too many steps. But it is free!