I’ve just created this script. You type text, and it records itself saying it into an aiff file.
The problem with it is that if you put a lot of text into it it never finishes it. When you hear the audio it stops at about 40-60 seconds. Can this be solved by script or is it just the way it’s meant to be?
on run
set textSpeak to the text returned of (display dialog ¬
"Enter the text to be spoken." default answer "Enter the text to be spoken here.")
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
choose from list voiceChoices
set chosenVoice to (choose from list voiceChoices)
say textSpeak using chosenVoice saving to ¬
":Users:mileshazan:Desktop:SpokenText.aiff"
end run
Model: iBook SE 366mHz
AppleScript: 1.9.1.
Browser: Safari 85.8.1
Operating System: Mac OS X (10.2.x)
I pasted an artical into the text field.
Worked fine.
3059 characters (depending on the voice ie. Albert 6.12 minutes, Victoria 3.12)
on run
set textSpeak to the text returned of (display dialog ¬
"Enter the text to be spoken." default answer "Enter the text to be spoken here.")
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
--choose from list voiceChoices
set chosenVoice to (choose from list voiceChoices)
say textSpeak using chosenVoice saving to ¬
":Users:user:Desktop:SpokenText_" & chosenVoice & ".aiff"
end run
I notice that Koala’s using Jaguar and AppleScript 1.9.1, where the 255-character text limit in ‘display dialog’ does apply. ‘say’, however, can cope with far more than that, so it would just be a matter of finding another way to get the text into the script. If it were saved from TextEdit, say, as a plain-text file, it could be read in like this:
on run
set textSpeak to (read (choose file with prompt "Choose a plain-text file containing the text to be spoken."))
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
set chosenVoice to (choose from list voiceChoices)
if (chosenVoice is false) then error number -128
say textSpeak using (item 1 of chosenVoice) saving to ¬
((path to desktop as Unicode text) & "SpokenText.aiff")
end run
‘display dialog’ is not a good way to type text. I suspect that you may be pasting text. If this is the case, then you can just get the clipboard text through AppleScript’s ‘the clipboard’. Wite back if this is what you’re doing.
Thanks for all the replies. I was copying and pasting so I used the clipboard method.
Here is the new script:
on run
set textSpeak to (the clipboard as string)
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
choose from list voiceChoices
set chosenVoice to (choose from list voiceChoices)
say textSpeak using chosenVoice saving to ¬
":Users:mileshazan:Desktop:SpokenText.aiff"
end run
I also tried Nigel Garvey’s text file method which works also.
Thanks
Model: iBook SE 366mHz
AppleScript: 1.9.1.
Browser: Safari 85.8.1
Operating System: Mac OS X (10.2.x)
I further improved my script by making it so you choose your file’s name, and it saves into a special folder. The only problem is that I’m trying to use a variable in a file path. I don’t know how. Is it possible? I have tried this with the variable chosenName.
on run
tell application "Finder"
if not (the folder "Text-to-Speech AIFF Files" of desktop exists) then
make new folder at ":Users:mileshazan:Desktop" with properties {name:"Text-to-Speech AIFF Files"}
end if
set textSpeak to (the clipboard as string)
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
choose from list voiceChoices
set chosenVoice to (choose from list voiceChoices)
set chosenName to text returned of (display dialog "What do you want to name your AIFF file?" default answer "SpokenText.aiff")
say textSpeak using chosenVoice saving to ¬
":Users:mileshazan:Desktop:Text-to-Speech AIFF Files:chosenName:"
end tell
end run
Model: iBook SE 366mHz
AppleScript: 1.9.1.
Browser: Safari 85.8.1
Operating System: Mac OS X (10.2.x)
Thanks for all the help. My script is finished now. Here it is:
on run
tell application "Finder"
if not (the folder "Text-to-Speech AIFF Files" of desktop exists) then
make new folder at ":Users:mileshazan:Desktop" with properties {name:"Text-to-Speech AIFF Files"}
end if
set textSpeak to (the clipboard as string)
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
choose from list voiceChoices
set chosenVoice to (choose from list voiceChoices)
set chosenName to text returned of (display dialog "What do you want to name your AIFF file?" default answer "SpokenText.aiff")
say textSpeak using chosenVoice saving to ¬
"Macintosh HD:Users:mileshazan:Desktop:Text-to-Speech AIFF Files:" & chosenName
end tell
end run
Model: iBook 366mHz
AppleScript: 1.9.1.
Browser: Safari 85.8.1
Operating System: Mac OS X (10.2.x)
Thanks, I was wondering why it asked me about voices twice. That was why.
on run
tell application "Finder"
if not (the folder "Text-to-Speech AIFF Files" of desktop exists) then
make new folder at ":Users:mileshazan:Desktop" with properties {name:"Text-to-Speech AIFF Files"}
end if
set textSpeak to (the clipboard as string)
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
set chosenVoice to (choose from list voiceChoices)
set chosenName to text returned of (display dialog "What do you want to name your AIFF file?" default answer "SpokenText.aiff")
say textSpeak using chosenVoice saving to ¬
"Macintosh HD:Users:mileshazan:Desktop:Text-to-Speech AIFF Files:" & chosenName
end tell
Model: iBook SE 366mHz
AppleScript: 1.9.1.
Browser: Safari 85.8.1
Operating System: Mac OS X (10.2.x)
Is there any way to change this script to work on any user on any mac?:
on run
tell application "Finder"
if not (the folder "Text-to-Speech AIFF Files" of desktop exists) then
make new folder at ":Users:miles:Desktop" with properties {name:"Text-to-Speech AIFF Files"}
end if
set textSpeak to (the clipboard as string)
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
set chosenVoice to (choose from list voiceChoices)
set chosenName to text returned of (display dialog "What do you want to name your AIFF file?" default answer "SpokenText.aiff")
say textSpeak using chosenVoice saving to ¬
"Macintosh HD:Users:miles:Desktop:Text-to-Speech AIFF Files:" & chosenName
end tell
end run
Model: Macintosh Server G4 (Gigabit Ethernet)
AppleScript: Script Editor 2.0 (v43.1), AppleScript 1.9.3
Browser: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en; rv:1.8.1.4) Gecko/20070509 Camino/1.5
Operating System: Mac OS X (10.3.9)
on run
tell application "Finder"
if not (the folder "Text-to-Speech AIFF Files" of desktop exists) then
make new folder at desktop with properties {name:"Text-to-Speech AIFF Files"}
end if
end tell
set textSpeak to (the clipboard as string)
set voiceChoices to {"Agnes", "Albert", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
set chosenVoice to (choose from list voiceChoices)
set chosenName to text returned of (display dialog "What do you want to name your AIFF file?" default answer "SpokenText.aiff")
say textSpeak using chosenVoice saving to ¬
((path to desktop) as unicode text) & "Text-to-Speech AIFF Files:" & chosenName
end run
Somebody more knowledgeable will have to explain why ((path to desktop) as unicode text) doesn’t work in the Finder tell block.
on run
tell application "Finder"
if not (the folder "Text-to-Speech AIFF Files" of desktop exists) then
make new folder at desktop with properties {name:"Text-to-Speech AIFF Files"}
end if
end tell
set textSpeak to (the clipboard as string)
set voiceChoices to {"Agnes", "Albert", "Alex", "Bad News", "Bahh", "Bells", "Boing", "Bruce", ¬
"Bubbles", "Cellos", "Deranged", "Fred", "Good News", "Hysterical", ¬
"Junior", "Kathy", "Pipe Organ", "Princess", "Ralph", "Trinoids", "Victoria", "Whisper", "Zarvox"}
set chosenVoice to (choose from list voiceChoices)
set chosenName to text returned of (display dialog "What do you want to name your AIFF file?" default answer "SpokenText.aiff")
say textSpeak using chosenVoice saving to ¬
((path to desktop) as unicode text) & "Text-to-Speech AIFF Files:" & chosenName
end run