Automator: Text to iPod

Mac OS 10.4 includes an application called “Automator” that allows end users to automate common tasks in limited ways without coding. I have some friends that commute to school (around 3 hours a day in the car). This means they have large amount of reading to do and a large amount dead-time in the car. Some of the reading is electronic, so they have been using the built-in text-to-speech features of the Mac. This is not ideal, however, because their is not a way to pause or skip around the reading. I suggested they convert the text to a speech sound file and play it on their iPods. So this is a tutorial to do that with Automator.

Technorati Tags: , ,



Automator Screen Shot

Start Automator. Above you can see the Automator window (click on the thumbnails for larger images). You can select an application (or group of actions) in the “Library” column and see the available actions in the “Actions”. You can then drag an action into the workflow area and connect actions together.

I like to start a workflow with a confirmation dialog just to make sure I’m running the correct thing. This is optional, but if you would like to add one select “Automator” in the library and drag the “Ask for Confirmation” action to the workflow area (The big blank area of the window). Type in a message (I used “Convert TextEdit Document to Speech.”) and an explanation. I used the following.

This will export the currently open document in TextEdit to an audio file and import it into iTunes as an ACC file. You may then export this to your iPod. The next dialog will ask which voice to use. The file’s location is not important; it will be deleted.

Next, we need to get text into our workflow. There are several ways to do this. I choose “Get Contents of TextEdit Document” under “TextEdit” because a) every mac user has it and b) you copy and paste text from anywhere without creating a text file. The following screenshot shows the action, the “Text” at the bottom of the image is the output of the action. So, we need an action that can handle text as it’s input.

figure 2

Now lets convert the text to speech. Select “TextEdit” in the library and drag “Text to Audio File” into the workflow under the “Get Contents of TextEdit Document”. Select the voice to use. I bought a voice from Cepstral that sounds kinda like a depressed NPR commentator, but the Mac includes a lot of voices for free. If you’ve got a thing for Stephen Hawking, I suggest the “Fred” voice. Type a filename into the “Save As” box. I left the “where” location pointing to the desktop because the workflow will delete this file anyway. If you click the arrow by “Options” you’ll see a check box labeled “Show Action When Run”. This doesn’t make sense at first look but with a little experimentation it became obvious. Check the box if you would like to change the settings for this action when it runs.

figure 3

You’ll notice that the output of the previous action has joined to the input of our new action. As one would expect, the output of the “Text to Audio File” action is “Files/Folders”. But what format is our audio file? Open TextEdit and type (or paste) some text and click the run button. An AIFF file is created. AIFF is an uncompressed audio format, meaning the file is very large. We need to compress the file and we still need to import it into iTunes. Luckily, the two things can happen at once. In fact the next action can even delete our temporary AIFF as an added bonus. Select “iTunes” in the library and drag the “Import Audio File” action to the bottom of the workflow.

figure 4

Set the encoder to “AAC Encoder” and check the “Delete source files after encoding” box. The output of this action is an iTunes song. So now, we have a nifty compressed sound file of the computer reading some text, but the only searchable information is the filename. Let’s add some metadata to our file so we can more easily find our track in iTunes. In the Automator library, select “iTunes” and drag the “Set Info of iTunes Songs” action to the bottom of the workflow.

figure 5

If you have every used the “Info” dialog in iTunes, this should look very familiar. Go ahead and set some defaults on this action. The screenshot shows what I used. You should set this up in whatever way you prefer; the point is to provide enough information to identify a track and build smart playlists. Alternately, you could use another action to add it to a normal playlist. Select “Show Action When Run” so we will be prompted for changes at runtime.

Our speech file is compressed and has decent metadata now, but anything longer than a few paragraphs might be interrupted. You need to make this track bookmarkable. Doing this manually is easy, select the track in iTunes and press Command-I to display info and check the “Remember playback position” (and maybe the “Skip when Shuffling”) boxes under the “Options” tab. But, this is an Automator tutorial, so we need to automate this step. I haven’t found a way to do this with the default set of actions, but Automator can be extended by downloading new actions. Save the workflow and close Automator.

To make a track bookmarkable, download Doug’s iTunes Automator Actions. Doug Adams has built several additional actions for iTunes and the package includes an installer. After installing the new actions, start Automator. At the bottom of the library, under “My Workflows” you’ll find the workflow saved earlier. Double click to load it in a new window. Select “iTunes” in the library and drag the new “Make AAC Tracks Bookmarkable” into the bottom of the workflow (or between the last two actions, doesn’t matter).

Now save your workflow again. You could add some more actions to deal with the iPod, but my setup would automatically copy this track on the next sync and that is good enough for me.

You can save the workflow as an application by using File>Save As… and select “Application” as the file format. This makes it quicker to use the workflow. When run as an application, you’ll see the status of the workflow displayed in the menubar. It seems that the workflow saves the values you put into the action prompts on each run. Also, note that to give someone your workflow, they must have all the applications and actions installed in the same places.

That’s a quick introduction to Automator. If you need more flow control you should look into using AppleScript or some other programming language.

Comments (1) to “Automator: Text to iPod”

  1. This is pretty sweet! I’ve never screwed around with the automator before. I wonder if I could use it to check blogs without rss feeds for mp3s to download (tried to kludge my way through with wget, got frustrated and quit).