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


Click here to return to the 'Speak a text file to AIFF' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Speak a text file to AIFF
Authored by: Eravau on Dec 19, '02 12:05:50PM
If you'd like to synthesize a lot of text (more than a small phrase in a dialog box), you can type it into a text file in your favorite text editor. Then you can run the following script:


set file_to_read to (choose file with prompt "What should I read?")
open for access file_to_read
set speak_me to read file_to_read
say speak_me saving to (choose file name with prompt ¬
"Save sound file..." default name "speak_me.aiff")


When it asks what file to read, jut choose the text file into which you typed your text. Or if you wanted, you could save a web page from your web browser as text (not as source) and have it read that file to you.



[ Reply to This | # ]
Speak a text file to AIFF
Authored by: Eravau on Dec 19, '02 05:12:28PM
Actually, it looks like I figured that out for nothing...


If you looke at one of Apple's AppleScript pages it has a couple of nice scripts with even more extensive abilities than the hint or mine.


One thing I would like to add, though... If you want a web page automatically saved to a text file (via AppleScript) for processing with one of these scripts, the best alternative I've found is using a do shell script command and running links (text-based web browser) with the -dump flag. For example:


do shell script "/sw/bin/links
-dump http://www.macosxhints.com/
> ~/Desktop/MacOSXHints"


(Note: the 3 bold lines above should be one line, but are broken for readability. Just rejoin them with a space at the end of each line above. This requires that you have the links web browser installed...which you can do with fink.)


...will dump a text-rendered version of the front page of this web site to a file on your desktop. You could then open the file manually with the script above...or just add it to the script and have it automatically go through all of the pages you want turned into audio files and download, open, and speak to file for each one.


You could probably even AppleScript iTunes to encode it to mp3 for you and sync it to your iPod so that you can have your favorite web pages read to you on the go. According to iTune's AppleScript dictionary, there are convert and update commands to do just these things.


Since I don't have an iPod, I didn't have enough motivation to work out all the syntax and write the script, but if somebody wants to give me an iPod for Christmas, I think I could work up enough energy to do that. = )


[ Reply to This | # ]

Speak a text file to AIFF
Authored by: hayne on Jan 03, '03 03:22:21AM

Here's a Bourne shell version (which is perhaps more convenient for use from the Terminal):

#!/bin/sh

# This script uses text-to-speech to convert the text in an ASCII text file
# to an audible form and saves it in an audio file.
# This script expects two command-line arguments:
# The first argument is the name of a text file
# The second argument is the name to use when saving the audio
# (the audiofile name should usually have a ".aiff" suffix)

message=`cat $1`
audiofile=$2

echo "set ofile to POSIX file \\"$audiofile\\"
say \\"$message\\" saving to ofile" | /usr/bin/osascript



[ Reply to This | # ]
backslash screw-up
Authored by: hayne on Jan 03, '03 03:26:08AM

Those double backslashes should be single backslashes.
(Geeklog's preview misled me)
The backslashes are for escaping the double quotes.



[ Reply to This | # ]