I made a little app that takes text and uses Macintalk to speak it, but with added features like saving the speech to an audio file and selecting a voice you want to use from within the app. I wrote it a while ago, so the code is pretty scatterbrained, but if you can sift through it, you may find it helpful.
I have no doubt that there are much better ways to program this so it’s more efficient and easy to read. If notice anything stupid about the syntax that I could be doing differently, please let me know. I’m always trying to improve!
I call it Speecher. Because that name is about as much of a real English word as the language that Mac speaks is the actual English language.
set list_of_voices to {"Alex", "Bruce", "Fred", "Junior", "Ralph", "Agnes", "Cathy", "Princess", "Vicki", "Victoria", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bubbles", "Cellos", "Deranged", "Good News", "Hysterical", "Pipe Organ", "Trinoids", "Whisper", "Zarvox"}
set audioFormats to {".au ", ".flac ", ".flv ", ".ogg ", ".wav ", ".wmv"}
set voice to "the default system voice."
set text_to_speak to ""
repeat
set voice to (choose from list list_of_voices with prompt "Select your voice or click Continue to use " & voice with title "Choose Your Voice" OK button name "Continue" cancel button name "Quit" with empty selection allowed)
if the result is false then return
repeat
set voice to voice as text
if voice is "" then set voice to "the default system voice."
set speechPrompt to (display dialog "Click Back to get a different voice, or to quit.
If nothing happens when you press the Speak button, try using a different voice.
Using " & voice & "
Enter some text to speak:" default answer text_to_speak buttons {"Back", "Save Audio", "Speak!"} default button 3 with title "Speecher")
if button returned of speechPrompt is "Back" then
exit repeat
else if button returned of speechPrompt is "Speak!" then
set text_to_speak to the text returned of speechPrompt
if voice is "the default system voice." then
say text_to_speak
else
try
say "" & text_to_speak & "" using "" & voice & ""
on error
exit repeat
end try
end if
else
set text_to_speak to the text returned of speechPrompt
if text_to_speak is "" then
display dialog "Enter some text!" buttons {"Back"} default button 1 giving up after 3
exit repeat
end if
set savePath to (choose file name with prompt ".AIFF FORMAT NEEDED FOR ITUNES PLAYBACK.
Quicktime not supported.
Other extensions include:
" & audioFormats & "" default name ".aiff" default location (path to documents folder))
try
say text_to_speak using voice saving to savePath
on error
if voice is "the default system voice." then
say text_to_speak saving to savePath
else
exit repeat
end if
end try
set text_to_speak to ""
set nextAction to the button returned of (display dialog "File saved!" buttons {"Quit", "Back to Speecher", "Show in Finder"} default button 2 with icon note)
if nextAction is "Quit" then
return
else if nextAction is "Back to Speech" then
exit repeat
else
tell application "Finder"
activate application "Finder"
reveal savePath
end tell
repeat
tell application "System Events"
set front_app to (item 1 of (get name of processes whose frontmost is true))
if front_app is "Speecher" then exit repeat
delay 0.1
end tell
end repeat
activate me
end if
end if
end repeat
end repeat