How to Convert a Text File into a Spoken Audio File via Command Line
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.
THANK YOU!! :D
hello sir i am writing simple C program .. hello world now i want output in voice so now what I do for that?
[…] 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 […]
better to over-engineered than under-engineere
[…] 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 […]
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
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.
Worked for me with “say -o audio.m4a -f text.txt”
What is this Services menu and why do I not have it?
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.
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.
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!
Try using a plain text TXT file rather than an RTF or any formatted document, does that work?
Thanks Will but that didn’t work.
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?
Wish I had this in college :p
did it work for you?