Speach Script Doesn't Finish

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)

Hi koala,

There is a 256 character limit on the text in the ‘default answer’. Maybe you can get the text some other way.

gl,

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

slightly cleaned

Hi.

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

Hi,

‘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.

gl,

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)

Hi Koala,

There’s several things you can change there but for now, in the string:

“:Users:mileshazan:Desktop:Text-to-Speech AIFF Files:chosenName:”

You cannot place the variable in the string, but need to concatentate:

“:Users:mileshazan:Desktop:Text-to-Speech AIFF Files:” & chosenName

Note that only references to folders end with colon while references to files don’t.

Edited: BTW, you should start the file path with the startup disk instead of the colon. e.g.

“Macintosh HD:Users:mileshazan:Desktop:Text-to-Speech AIFF Files:” & chosenName

Starting with the colon might not work in the future.

gl,

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)

You do not need the first

 choose from list voiceChoices

the line:

 set chosenVoice to (choose from list voiceChoices)

works on its own

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.

Thank you for the script. It works fine on any user now.

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

Now it works with Leopard.:stuck_out_tongue: