How to Convert a Text File into a Spoken Audio File via Command Line

Jun 28, 2011 - 16 Comments

terminal Using Mac OS X Text to Speech tools, we can convert any .RTF or .TXT file into a spoken audio file which can then be transferred to your iPod or iPhone for later listening.

Update: There is an easier way to do a text to audio file conversion using the OS X Services menu, the resulting spoken audio track goes directly into iTunes, you may want to try that first if you do not prefer the command line approach we cover here.


The command format to convert a text document into an m4a audio file is as follows:

say -o output.m4a -f /path/to/file.txt

The default output will be to the Terminals present working directory (usually your Home), but you can specify it to go elsewhere if you want. Here’s an example, with the output going to the desktop and the input file coming from a documents folder:

say -o ~/Desktop/textaudio.m4a -f ~/Documents/HugeDocumentNobodyWantsToRead.txt

If you want to use a text file that is buried deep somewhere on your Mac, remember you can drag and drop the icon into the Terminal to display it’s full path.

The audio file will be in M4A format and be read as whatever your current default text-to-speech voice is. If you’d rather have an mp3 file, just use iTunes to convert m4a to mp3, and you can always change the voice with the -v flag or by setting the default to something different.

Update: If you are having any problems, try using a plain text .txt file as the input document.

.

Related articles:

Posted by: William Pearson in Mac OS, Tips & Tricks

16 Comments

» Comments RSS Feed

  1. Andrew says:

    THANK YOU!! :D

  2. chetan says:

    hello sir i am writing simple C program .. hello world now i want output in voice so now what I do for that?

  3. […] forget that you can also convert a text file to a spoken audio file, this can be achieved through the command line or by using the simpler “Add to iTunes as […]

  4. mike says:

    better to over-engineered than under-engineere

  5. […] showed you how to convert text to spoken audio files via the command line but some people ran into trouble with that method. It turns out I completely over-engineered how to […]

  6. Ty says:

    Seriously, don’t even bother with Terminal and command line stuff. Just use Automator. They have a prebuilt workflow that does all the work for you to include putting your highlighted text/copied to the clipboard right into an iTunes file. No fuss, no key commands. Just a sweet one click solution.

    http://automator.us/leopard/examples/ex07/index.html

  7. mike says:

    all os x users have services menu. In all apps under the applications name in the menubar, same menu selection you get to the about this application or preferences for the app. hope this helps.

  8. Sven says:

    Worked for me with “say -o audio.m4a -f text.txt”

    What is this Services menu and why do I not have it?

  9. TY says:

    Never mind guys. I found a much better source that take all the effort out of this. No Terminal. No Commands. Just point and click:

    http://automator.us/leopard/examples/ex07/index.html

    Thanks Rob.

  10. mike says:

    I just open text files, web pages select all or the text i want then go to services menu and select add to itunes as a spoken track.

  11. TY says:

    Playing w/ the Convert a Text File into Spoken Audio function but the command only creates an audio file that speaks the name of the original file? A step must be missing or I am doing something wrong. Please help. This would be a HUGE asset!

  12. Rob says:

    The conversion of a .rtf to .m4a works; but the only audio being output is the file name. For example the test file “test.rtf” – the file is converted but the .m4a file name is what is read to me. Not the text in the file. What am I don’t wrong?

  13. Peter says:

    Wish I had this in college :p

Leave a Reply

 

Shop on Amazon.com and help support OSXDaily!

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates

Tips & Tricks

News

iPhone / iPad

Mac

Troubleshooting

Shop on Amazon to help support this site