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


Click here to return to the '10.7: Install the new voices' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.7: Install the new voices
Authored by: withdave on Jul 23, '11 11:59:43PM
Here is a Lion Cocoa-Applescript Applet to demo all your installed voices. For each voice it puts up a dialog with information about gender, age and locale then speaks the voice's demonstration text. The dialog automatically OK's after 5 seconds. Click Cancel to stop.

This script uses new Applescript capabilities only available in Lion. To run it create a new script in Script Editor by chosing menu File -> New From Template -> Cocoa-Applescript Applet then replace all text with the following:

property NSSpeechSynthesizer : class "NSSpeechSynthesizer"

on run
	try
		set allVoices to NSSpeechSynthesizer's availableVoices()
		repeat with voice in allVoices
			set voice to voice as text
			
			set voiceName to voice -- VoiceName attribute will override
			set gender to missing value
			set lang to missing value
			set locale to missing value
			set age to missing value
			set demoText to missing value
			
			-- Access voice attributes
			set attrs to NSSpeechSynthesizer's attributesForVoice_(voice as text)
			set keys to attrs's allKeys()
			
			repeat with aKey in keys
				set aKey to aKey as text
				if aKey is "VoiceName" then
					set voiceName to attrs's objectForKey_(aKey) as text
				else if aKey is "VoiceGender" then
					set gender to attrs's objectForKey_(aKey) as text
				else if aKey is "VoiceLanguage" then
					set lang to attrs's objectForKey_(aKey) as text
				else if aKey is "VoiceLocaleIdentifier" then
					set locale to attrs's objectForKey_(aKey) as text
				else if aKey is "VoiceAge" then
					set age to attrs's objectForKey_(aKey) as text
				else if aKey is "VoiceDemoText" then
					set demoText to attrs's objectForKey_(aKey) as text
				end if
			end repeat -- attributes
			
			set info to voiceName & " "
			if gender is not missing value then set info to info & gender & " "
			if locale is not missing value then
				set info to info & locale & " "
			else
				if lang is not missing value then set info to info & lang & " "
			end if
			if age is not missing value then set info to info & "age " & age & " "
			display dialog info giving up after 5
			
			set speakThis to "There is no demo text to speak for this voice."
			if demoText is not missing value then set speakThis to demoText
			say demoText using voiceName volume 1
			
		end repeat -- voices
		
	on error errMsg number errNum
		if errNum is not -128 then -- no error dialog if user simply canceled
			activate
			display dialog errMsg
		end if
	end try
	
	tell me to quit
end run
</code>


[ Reply to This | # ]