Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Convert text to iTunes audio book via Services item Apps
After reading this hint on macosxhints about how to create an audio file from text, I figured the process could probably be streamlined a bit. So, I created a Service (that appears in the Services menu) that operates on selected text. Select the plain text in your source location (text file, web page, email, etc.) and then select Services » Speak to iTunes Audiobook to speak the text into a track that will appear in the Audiobooks section of iTunes. Just remember to set the encoder quality beforehand in iTunes, because it's not configurable through AppleScript (I recommend using 'Spoken podcast').

Package download [40KB]

For those curious few, the AppleScript within the service is as follows:
on process(input)
  set theOriginalPath to (path to desktop folder as string) & "Speech.aiff"
  
  -- Speak text
  say input using "Alex" saving to theOriginalPath
  tell application "iTunes"
    -- Import AIFF audio
    set theOriginaliTunesFile to (add theOriginalPath)
    tell application "Finder" to delete theOriginalPath
    -- Prepare AAC encoder
    set lastEncoder to current encoder
    set newEncoder to (item 1 of (every encoder whose format is "AAC"))
    set current encoder to newEncoder
    -- Convert to AAC
    set theM4aFile to item 1 of (convert theOriginaliTunesFile)
    set current encoder to lastEncoder
    -- Remove original
    delete theOriginaliTunesFile
    set fileLocation to location of theM4aFile
    -- Set as audio book type
    tell application "Finder"
      set theFile to fileLocation as alias
      set file type of theFile to "M4B "
      if name extension of theFile is not "m4b" then
        set name of theFile to ((text 1 thru -((length of (get name extension of theFile)) + 1) of (name of theFile as text)) & "m4b") as string
      end if
    end tell
    -- Remove from iTunes, and re-add
    delete theM4aFile
    set theNewTrack to add theFile
    -- Select in iTunes
    reveal theNewTrack
  end tell
end process
[robg adds: I tested this, and it works as described. The service is installed in the top-level /Library » Services menu, and can be removed by simply deleting SpeakToItunesAudiobook.service in that folder. Once installed, you need to refresh the Services menu to see the new service; you can do that by logging out and in, by using one of the methods described in this older hint and its comments, or by using a third-party program such as ServiceScrubber. Note that this is set to 10.5 Only due to the use of the Alex voice; I'm not sure if it would run on 10.4 with a different voice, or if there are other AppleScript commands in the script that are 10.5 only as well.]
    •    
  • Currently 1.50 / 5
  You rated: 2 / 5 (10 votes cast)
 
[43,154 views]  

10.5: Convert text to iTunes audio book via Services item | 11 comments | Create New Account
Click here to return to the '10.5: Convert text to iTunes audio book via Services item' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Convert text to iTunes audio book via Services item
Authored by: lgc90 on May 09, '08 08:24:36AM
For those not looking to save the resulting audio file in iTunes and/or as an audiobook, "lips" is a freeware tool to convert any text to an audio file with any desired voice and speed.

http://superpixel.ch/software/lips/


[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: thiefhunter on May 09, '08 09:11:24AM

"Installation failed because some files could not be installed in '/Library/Services.'" Succeeded only by changing install location to user library.



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: thiefhunter on May 09, '08 09:31:15AM

This is fantastic. Thanks a million, miketyson (and Rob).



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: Angstrom Burnout on May 10, '08 01:54:00PM

does not work. installer could not create folder.



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: maxmaxmax123 on May 11, '08 10:52:22AM

when it started the actual download, it came up with a message saying "could not create '/Library/Services'" i believe someone else had the same problem, so its not just my computer messing up. plus, if its saying could not CREATE and it already exists, then i assume thats a problem. or is it just abbreviating the whole file name? I'm just trying to fix this for you. Thanks in advance.



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: miketyson on May 11, '08 09:51:53PM

Ah yeah, the installer problem's my bad - I didn't like it asking for password when installing to user folder, but it needs it when installing to system folder.

I've re-added it, so should work properly now.



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: spynotebook on May 12, '08 07:35:56AM

There are several longer blog posts that I come across every day that I don't really want to read then. This makes it easy to send over to iTunes to listen in the car or at the gym.

I would like to mark these with a custom genre (Converted Text) or add them to a custom playlist automatically. This way, it would be a snap to sync the unlistened to ones to the iPhone.

Is there an easy way to do this?



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: spynotebook on May 12, '08 12:19:31PM

that was easy. after about 2 seconds of googling, i tried adding

set genre of theNewTrack to "Converted Text"

towards the end of the script and it seemed to work.



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: mtaylorGT on May 12, '08 07:43:08AM

Any quick and easy way to make this script produce mp3 files instead?



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: asmeurer on May 13, '08 08:41:10PM

It seems like some of the scripts at dougscripts.com are able to set the encoder. You might want to check them out.

Or I could be wrong.



[ Reply to This | # ]
10.5: Convert text to iTunes audio book via Services item
Authored by: thiefhunter on May 15, '08 03:29:07PM

This is a fantastic hint/script. I find it easier to listen to Alex if I slow his speech a little, in system prefs. Strangely, some time after doing some conversions, my machine lost all audio input and output, with no devices supported according to Audio Midi Setup. Removing the service from its folder restored audio. I will experiment with this. Perhaps the issue won't occur again, or perhaps I'll just have to drop the service in when I want do do a conversion. We'll see.

---
Thiefhunters in Paradise



[ Reply to This | # ]