Text to iTunes shell script

Posted on Friday, November 21, 2008

When I posted my automator workflow for turning text to speech and importing the result into iTunes, I admitted I felt like I was giving up a bit by failing to write a shell script to do this and settling for an Automator workflow.

The primary advantage of a shell script: it makes it easier to ssh into a computer remotely (in my case, my iMac at home, where I keep my iTunes library) and run the script via command line. Yes, you can use the automator command, but any interactivity with Automator still goes through the GUI, which obviously won’t work when you’re connecting remotely to a Mac via the command line. Yes, you can pass variables into the automator command to address this, but…look, I just wanted to do it without Automator, ok? And now I have!

With the exception of mp4tags for setting ID3 tags on the mp4 audio files (which you can get here or by installing the macports package mpeg4ip), this script uses only built-in commands available with OS X 10.5. It takes one argument: a plain text file with the text you want to speechify.

Liquid error: No such file or directory – pygmentize -l bash -O encoding=utf-8 -f html

So my normal use of this: ssh to my iMac that holds my iTunes library, open vim, paste in whatever text I want to turn to speech (make sure you set your terminal to UTF-8 if you have problems with garbled characters) and run text2itunes mytextfile.txt. It will prompt you for a track title and then do its work.