Hack 24. Convert Text to Audio for Your PSP
Why buy audiobooks for your PSP when you can make your own? You like books, but you don't particularly like the idea of reading your books on your PSP's screen. (If you do want to read books on your PSP, make sure you check out "Use Your PSP as an E-Book Reader" [Hack #27] and "Create Your Own PSP E-Books" [Hack #29].) You've been considering buying some audiobooks and listening to them on your PSP, but you'd rather spend those hard-earned dollars on games for your PSP. Why not simply make your own audiobooks for the PSP? Don't worry. I'm not suggesting you sit down and read James Joyce's Ulysses out loud while recording it to MP3. Instead, just grab the text of Ulysses from Project Gutenberg (http://www.gutenberg.org/) for free and have your computer read the text to audio files. 3.5.1. Get the TextYou can do this with any plain text file you have lying around, so don't be afraid to take that business report your boss wants you to review, convert it into plain text, and change it over to audio. Since the PSP is a recreational device, however, I am going to assume that you are looking for some actual reading entertainment. If that's the case, a wide variety of options are readily available to you via the Internet. Both Project Gutenberg (http://www.gutenberg.org) and the Electronic Text Center at the University of Virginia Library (http://etext.lib.virginia.edu/) freely offer a variety of literary titles that have fallen out of copyright and entered into the public domain. The text section of the Internet Archive (http://www.archive.org/details/texts) contains texts that have entered into the public domain and others that have been released under Creative Commons licenses or are free from any sort of copyright. The Creative Commons web site itself features a text section (http://creativecommons.org/text/) that regularly highlights texts that have been released under Creative Commons licenses. In addition to these resources, you can easily copy and paste the text of any web document into a .txt file, or even use an online RSS feed reading tool like Bloglines (http://www.bloglines.com) to display your daily dose of news items on one web page where you can select all, copy, and paste into a .txt file. 3.5.2. Text to SpeechAfter you've picked out a text that you'd like to listen to, it's time to convert that document to MP3. Now, if you've picked out a particularly long document, such as the aforementioned Ulysses by James Joyce, you will most likely need to break the text up into separate documents to be made into separate audio files for manageable listening. You could either follow the natural structure of the book, separating the document into individual chapter text files, or do something more arbitrary, like breaking the document into separate files every 3050 pages. Once you have your documents ready to go, you need a tool to convert them to MP3 format. A quick search of VersionTracker (http://www.versiontracker.com) will turn up a variety of shareware and commercial titles for Windows that will convert text files to audio files. If you conduct the same search on the Mac OS X end of things, you'll find several freeware titles in the mix. This is because Mac OS X has integrated text-to-speech support built into the OS. Here's how you can convert text to speech under Windows, Linux, and Mac OS X. Your end result will be an audio file that you can convert as described in the next section. 3.5.2.1. Windows.If you are on Windows, use a third-party text-to-audio program such as VoiceMX Studio (http://www.tanseon.com/products/voicemx.htm), load the text, and generate your output file (in the case of VoiceMX Studio, you'll get a .wav file). Next, convert the file to MP3 as described later in this hack, then take the resulting file and drop it in /PSP/MUSIC/ on your Memory Stick to listen. 3.5.2.2. Linux.The open source Festival (http://www.festvox.org) includes an application called text2wave, which reads in a text file and outputs a .wav file. You may be able to find Festival in your Linux distribution's package repository, so check there before installing from the source. Once you've got the .wav file out of text2wav, you can convert it and drop it into /PSP/MUSIC/ on your Memory Stick. By default, text2wave will read from standard input and dump its .wav to standard output. You can create a file with a command such as text2wave input.txt -ooutput.wav. You can change text2wave's settings by evaling a valid festival command. For example, to change the voice to voice_kal_diphone, you'd do this: text2wave input.txt -o output.wav -eval "(voice_kal_diphone)" 3.5.2.3. Mac OS X.Launch your Terminal (located in /Applications/Utilities/). Now, assuming the text file that you want to convert is called text.txt and is located on your Desktop, at the command line, type the following: sayf ~/Desktop/text.txto ~/Desktop/text.aiff This string will read the text.txt file on your Desktop to a new AIFF file on your Desktop called text.aiff, using the default System voice settings you have defined in the "Text to Speech" section of your Speech control panel (System Preferences Speech Text to Speech).
3.5.3. Converting Your Speech FileNow all you have to do is take the resulting AIFF or WAV file and drop it into iTunes, then select the file and choose Advanced Convert Selection to MP3 to let iTunes convert the file to an MP3.
After converting the file, select the freshly converted version of the file and select File Show Song File to display the MP3 in the Finder. Simply drag the file over to your PSPs mounted Memory Stick and drop it into /PSP/MUSIC/, so that you can listen to it on the PSP. 3.5.4. Hacking the HackAutomation is the way to hack this hack. Mac users can create an AppleScript droplet that takes any .txt file that you drop onto it, and uses do shell script to run the appropriate say command, then grab the resulting file, import it into iTunes, convert it to MP3, and move the resulting file to the Music folder on your PSP. Such a script is beyond my novice AppleScripting skills. If you're interested in this, but not sure how to pull it off, may I suggest O'Reilly's AppleScript: The Definitive Guide? Of course, if you have Mac OS X 10.4 Tiger, you could easily do this with an Automator action [Hack #25]. Since LAME and text2wave are both command-line tools, it's easy to automate this process on Linux. For example, you can make your MP3 with one command line: text2wave input.txt | lame - output.mp3 |