Friday, August 22, 2014

#1 2008-05-20 02:48:50 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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 big_smile

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


Visit a great website, www.silverleaph.com

Filed under: voice

Offline

 

#2 2008-05-20 04:09:53 am

Martin Michel
Administrator
From: Berlin, Germany
Registered: 2008-03-03
Posts: 701
Website

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

Hi Sendura,

I may have misunderstood you, but anyway, here I go big_smile

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):

Applescript:


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:

Applescript:


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


Plonum - Convert images to iWork Numbers documents

Offline

 

#3 2008-05-20 04:27:01 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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

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

HOWEVER (always a problem sad)

When I run this:

Applescript:

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

Last edited by Sendura (2008-05-20 04:32:25 am)


Visit a great website, www.silverleaph.com

Offline

 

#4 2008-05-20 04:37:42 am

Martin Michel
Administrator
From: Berlin, Germany
Registered: 2008-03-03
Posts: 701
Website

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

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.


Plonum - Convert images to iWork Numbers documents

Offline

 

#5 2008-05-20 05:03:45 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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

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?


Visit a great website, www.silverleaph.com

Offline

 

#6 2008-05-20 05:13:34 am

Martin Michel
Administrator
From: Berlin, Germany
Registered: 2008-03-03
Posts: 701
Website

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

Would you like me to post the way here for future reference for yourself or anyone else?

New insights are ALWAYS welcome big_smile 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:

Applescript:


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


Plonum - Convert images to iWork Numbers documents

Offline

 

#7 2008-05-24 06:18:51 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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

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 tongue)
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)

Last edited by Sendura (2008-05-24 06:19:17 am)


Visit a great website, www.silverleaph.com

Offline

 

#8 2008-06-09 05:29:43 am

halbtuerke
Member
Registered: 2008-01-30
Posts: 11
Website

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

Sendura wrote:

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 tongue)
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

Offline

 

#9 2008-06-09 06:41:44 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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

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

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


Visit a great website, www.silverleaph.com

Offline

 

#10 2008-06-09 06:52:28 am

halbtuerke
Member
Registered: 2008-01-30
Posts: 11
Website

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

Sendura wrote:

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

Model: MacBook (Black tongue)
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

Offline

 

#11 2008-06-10 02:05:16 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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

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:

Applescript:

say "Hello World!" using "Trinoids"

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

Applescript:

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

This may be a simple script, but it works fine 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):

Applescript:

global sysVoice

Hope that this helped you smile

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


Visit a great website, www.silverleaph.com

Offline

 

#12 2008-06-10 03:09:00 am

halbtuerke
Member
Registered: 2008-01-30
Posts: 11
Website

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

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

Offline

 

#13 2008-06-10 03:25:35 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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

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 tongue)
AppleScript: 2.2
Browser: Firefox 2.0.0.14
Operating System: Mac OS X (10.5)


Visit a great website, www.silverleaph.com

Offline

 

#14 2008-06-10 04:47:59 am

halbtuerke
Member
Registered: 2008-01-30
Posts: 11
Website

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

Sendura wrote:

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

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

Sendura wrote:

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!

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

Read in English:

Applescript:

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:

Applescript:

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


Filed under: System

Offline

 

#15 2008-06-10 04:58:52 am

Sendura
Member
Registered: 2008-04-22
Posts: 15

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

Thanks for that smile

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

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


Visit a great website, www.silverleaph.com

Offline

 

#16 2008-06-10 05:08:59 am

halbtuerke
Member
Registered: 2008-01-30
Posts: 11
Website

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

Sendura wrote:

Thanks for that smile

You're welcome.

Sendura wrote:

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

You gave my mind a little inspiration, that's enough… tongue

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.198 seconds, 8 queries executed ]

RSS (new topics) RSS (active topics)