Simple thing turned not quite so simple... System Voice

Hi, wondering if anyone would be able to tell me how to CHANGE the system voice not this:
say “Hello World!” using “Alex”

Thanks in advance :smiley:

Model: MacBook (Black :P)
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

Hi Sendura,

I may have misunderstood you, but anyway, here I go :smiley:

The current system voice is stored in the following preferences file:

~/Library/Preferences/com.apple.speech.voice.prefs.plist

You can change it with the following command to the voice of your choice (e.g. Vicki):


do shell script "defaults write ~/Library/Preferences/com.apple.speech.voice.prefs SelectedVoiceName 'Vicki'"

And how to get all available voice names? Well, a Python script like this can be of great help (on Mac OS X 10.5 or on a Mac OS X where PyObjC is installed):

#!/usr/bin/python

from AppKit import NSSpeechSynthesizer

def getvoicenames():
“”“I am returning the names of the voices available on Mac OS X.”“”
voices = NSSpeechSynthesizer.availableVoices()
voicenames = []
for voice in voices:
voiceattr = NSSpeechSynthesizer.attributesForVoice_(voice)
voicename = voiceattr[‘VoiceName’]
if voicename not in voicenames:
voicenames.append(voicename)
return voicenames

if name == ‘main’:
voicenames = getvoicenames()
for voicename in voicenames:
print voicename.encode(‘utf-8’)

Just execute it from within an AppleScript like follows:


set pyscriptpath to POSIX path of ("Macintosh HD:Users:martin:Desktop:voices.py")
set voicenames to paragraphs of (do shell script "/usr/bin/python " & quoted form of pyscriptpath)

But maybe your question was targeted at another problem :wink:

Thanks for that! The change voice was all I need, nothing else :slight_smile: Thanks for going to all that trouble.

HOWEVER (always a problem :()

When I run this:

do shell script "defaults write ~/Library/Preferences/com.apple.speech.voice.prefs SelectedVoiceName 'Vicki'"

Nothing happens :l If you could help further that would be great!

ETA (Edit to add): I have just looked in the plist file and my voice is set to Vicki, however whenever I use speech, it comes out with Alex :l

I am sorry, it does not seem to be sufficient to just pass the name of the new voice using the «defaults» command, you also have to adjust the values for SelectedVoiceID & SelectedVoiceCreator…And I don’t know a way how to get those additional values.

Ok, thanks for that! I’ll fiddle around with the shell scripts for each name and see if I can get it to work! Would you like me to post the way here for future reference for yourself or anyone else?

New insights are ALWAYS welcome :smiley: So thanks in advance! And good luck…

P.S.: I just thought about that: One could try to set the voices in System Preferences and then look inside the preferences file to see the different values of the different voices. This way one could create several lists to choose from:


-- just bogus values
set voicenames to {"Agnes", "Alex"}
set voiceids to {"41", "45"}
set voicecreators to {"1836346163", "1836346164"}

Just a warning, I, when changing the VoiceID’s etc, only succeeded in completely messing up my speech plist file. If you happen to do the same thing, just remove the file and delete it. Your computer will make a new one (intact) as soon as you open speech in System Preferences.

I succeeded what I needed, simply by making the variables I had, global.

Thanks for your help!

Model: MacBook (Black :P)
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

Hi Sendura,

could you please give an example how it’s possible to change the default voice via AppleScript?

Thanks in advance

Would you like to know how to permanently change it, or temporarily, using a variable?

Model: MacBook (Black :P)
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

I just want to switch between 2 different voices so that Leopard can read english and german text, depending on my needs. So I would say permanently.

Thanks

Sorry I didn’t say all this last time, I didn’t have much time to reply and wanted you to know that I HAD actually read your question.

From testing, I was not able to change the voice permanently. I only succeeded in completely stuffing up speech on my Mac. If you want to experiment more go to Macintosh HD/Users/(Yourusername)/Library/Preferences/com.apple.speech.voice.prefs.plist
If you also succeed in messing up the system speech, all you need to do is delete the speechprefs plist file.

If you have Mac Leopard, the default system voice is Alex. To use a different voice without changing it permanently you can just use this script:

say "Hello World!" using "Trinoids"

You can also set this as a variable, so the voice can change multiple times during the script:

set sysVoice to "Bruce"
say "Hello World!"
say "Hello World" using sysVoice

This may be a simple script, but it works fine :slight_smile:

Also, to make it so this variable (sysVoice) can be changed multiple times throughout a script (if you are using Xcode) put this at the very beginning of your script (after the personal company details, etc):

global sysVoice

Hope that this helped you :slight_smile:

Model: MacBook (Black :P)
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

Thanks Sendura. Do you happen to know if there’s something like “get selected text” in Applescript, so I can feed this into the script?

Thanks in advance

Are you attempting to create a program that says out loud whatever someone highlights, in either German or English?

If so, I am not sure I can help you… I do not know much of keyboard and mouse related applescript, having not needed to use much in any of the applications I’ve made. Sorry!

If there is anything else you need, feel free to ask, though I will have a look for the highlighted text command.

Model: MacBook (Black :P)
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

Yep, that’s exactly what I’m trying to achieve.

I played a little bit with GUI-scripting and it seems like it actually works. :smiley:

Read in English:

set app_path to (path to frontmost application as string)
set mySelection to ""

tell application app_path to activate
tell application "System Events"
	keystroke "c" using command down
	delay 1
	set mySelection to the clipboard as text
	say mySelection using "Ryan Infovox iVox HQ"
end tell

Read in German:

set app_path to (path to frontmost application as string)
set meinText to ""

tell application app_path to activate
tell application "System Events"
	keystroke "c" using command down
	delay 1
	set meinText to the clipboard as text
	say meinText using "Klaus Infovox iVox HQ"
end tell

Everyone who wants to use this method has to check the “Enable access for assistive devices” in the Universal Access System Preference pane. If you want I can put some validation code into the script so it checks if it’s enabled or not.

Greetings

Thanks for that :slight_smile:

Sorry I couldn’t help more than I did, still not in my right mind after the flu.

Model: MacBook (Black :P)
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

You’re welcome.

You gave my mind a little inspiration, that’s enough. :stuck_out_tongue: