Page 1 of 2

get the current SpeechSpeed

Posted: Wed Aug 04, 2010 10:52 am
by jmburnod
Hi All,

Is there a way to get the current SpeechSpeed ?
I have seen a revSetSpeechSpeed command but not a revGetSpeechSpeed
These are the correct values. Internaly the system preferences "speech" the slider has values from 1 to 401, 200 being the middle value.
revSpeechSpeed 150 = 200 in the system preferences ?

Best

Jean-Marc

Re: get the current SpeechSpeed

Posted: Wed Aug 04, 2010 3:58 pm
by dunbarx
I don't see a property like the one you are asking for. But I cannot find the milk in the refrigerator.

Perhaps you can set the speechSpeed and store that value in a custom property?

Re: get the current SpeechSpeed

Posted: Wed Aug 04, 2010 4:45 pm
by jmburnod
Perhaps you can set the speechSpeed and store that value in a custom property?
Yes, but the user can set the speechSpeed in the system preferences and
i need to know it to set the value of a slider on openstack

Re: get the current SpeechSpeed

Posted: Thu Aug 05, 2010 11:51 pm
by Mark
Hi

Use the rate speech command:
revSpeak "[[rate 240]] hello there"
More info at http://qurl.tk/ei

Best,

Mark

Re: get the current SpeechSpeed

Posted: Sat Aug 07, 2010 10:19 am
by jmburnod
Hi,
And thank for your help
I found something about GetSpeechRate in the link http://qurl.tk/ei
but i don'n know how i can use it in rev.

Best

Jean-Marc

--••GetSpeechRate

Gets a speech channel’s current speech rate.

OSErr GetSpeechRate (
SpeechChannel chan,
Fixed *rate
);

Parameters

chan

The speech channel whose rate you wish to determine.
rate
On return, a pointer to the speech channel’s speech rate in words per minute, expressed as an integer value.

Return Value

A result code. See “Speech Synthesis Manager Result Codes.”
Availability

* Available in CarbonLib 1.0 and later when Text to Speech 1.0 or later is present.
* Available in Mac OS X 10.0 and later.

Declared In
SpeechSynthesis.h
--••GetSpeechRateEND

Re: get the current SpeechSpeed

Posted: Sat Aug 07, 2010 10:32 am
by Mark
Hi Jean-Marc,

Getting the default speech rate from the system preferences might need an external. I haven't found a way to do it with AppleScript yet.

Best,

Mark

Re: get the current SpeechSpeed

Posted: Sun Aug 08, 2010 12:09 am
by bn
Hi Jean-Marc,

the only way I found to get at the speechRate is via applescript and graphical user interface scripting (GUI scripting). This is always "ugly". It only works if the preference panes stay the same across system versions etc.
I tried to get at the pList. As it turns out the speech rate in system preferences and in the pList are not the same. I suspect there is a value in the pList that depends on the voice the user has chosen. So scripting the system preferences was the only consistent way.

Maybe someone finds a more elegant way (shell anyone?)

You have to decide whether you want to go with this script or you find it too complicated to test for all the System versions if it works. It works for me OSX 10.6.4. I guess it will work in other versions, but I can not test it right now.

For this script to work in system preferences you have to turn on in Accès universel: Activer l'acces pour les péripheriques d'aide

The script uses numbers instead of name of objects to be independent of the chosen language.

Code: Select all

tell application "System Preferences"
	set current pane to pane "com.apple.preference.speech"
	delay 0.5 -- adjust in case to fast
end tell

tell application "System Events"
	tell application process "System Preferences"
		tell window 1 --"Sprache" language	
			tell tab group 1
				click radio button 2
				delay 0.5 -- adjust in case to fast
				tell slider 1
					tell attribute 13
						set x to value
					end tell
				end tell
			end tell
		end tell
	end tell
end tell

tell application "System Preferences" to quit

return x
put this into a field, make a second field and a button
script of button:

Code: Select all

on mouseUp
   put field 1 into tAS
   do tAS as applescript
   put the result into tSpeechRate
   put tSpeechRate into field 2
end mouseUp
I attach the stack that works for me (attention, there is no errorchecking in both scripts, you might have to adjust the delays if half a second is not enough on a very slow machine)

regards, et bonne chance
Bernd

EDIT: see below for a newer version

Re: get the current SpeechSpeed

Posted: Sun Aug 08, 2010 8:56 am
by Mark
Nice solution, Bernd! I wouldn't use this for my commercial products, but for automating processes it is a great solution. Thanks for posting.

Mark

Re: get the current SpeechSpeed

Posted: Sun Aug 08, 2010 9:21 am
by bn
Mark,
thank you. Script Debugger was a big help, as always with applescript.

regards
Bernd

Re: get the current SpeechSpeed

Posted: Sun Aug 08, 2010 6:17 pm
by jmburnod
Hi Bernd,

And thank one more

I tested getSpeechRateASII.rev on two macs

1. powerbook G4 10.4.2 : return (512, 192)

2. Intel Core duo 10.5.6 : return 1.0

If i set the speedspeech with the slider of the system preferences, i have always the same result

Best

Jean-Marc

Re: get the current SpeechSpeed

Posted: Sun Aug 08, 2010 6:30 pm
by bn
Jean-Marc,

I will test it tomorrow on system 10.5x and 10.4.x
That is the problem with gui scripting, that it often depends on the system version.

regards
Bernd

Re: get the current SpeechSpeed

Posted: Sun Aug 08, 2010 9:55 pm
by Mark
Hi,

I did some tests, too. On a PowerMac G4 with 10.4.11, I always get (408,192). On an MacBook with OSX 10.6.4, I get either 1.0, or 100.0 or 200.0. If I set the speech rate to anything higher than half of the maximum, the value returned is always 200.0. If I set the speech rate to a value less than half of the maximum, then the values returned seem to be somewhat random.

Best,

Mark

Re: get the current SpeechSpeed

Posted: Mon Aug 09, 2010 1:26 pm
by bn
Hi,

I think I found the problem. I addressed the attribute by number instead of name. Numbers of attributes dont seem to be stable across systemversions etc.
Instead of tell attribute 13 I now use set x to value of attribute "AXValue"
This works for me on different computers under 10.4.x, 10.5.x and 10.6.x
I also tried
tell value indicator 1
set x to value
end tell
which I would have preferred, but it does not work under 10.4x.
Oh well, the joys of GUI scripting.

the script that works for me:

Code: Select all

tell application "System Preferences"
	set current pane to pane "com.apple.preference.speech"
	delay 0.5 -- adjust in case to fast
end tell

tell application "System Events"
	tell application process "System Preferences"
		tell window 1 --"Sprache" language	
			tell tab group 1
				click radio button 2
				delay 0.5 -- adjust in case to fast
				tell slider 1
					set x to value of attribute "AXValue"
				end tell
			end tell
		end tell
	end tell
end tell

tell application "System Preferences" to quit

return x
the button script:

Code: Select all

on mouseUp
   put field 1 into tAS
   do tAS as applescript
   put the result into tSpeechRate
   if tSpeechRate is not a number then put "Error" into field 2
   put trunc (tSpeechRate) into field 2
end mouseUp
the stack is appended

I would be greatful if someone could test the stack on different MacOSX computers for 10.4, 10.5, 10.6. I dont dare to think it works under 10.3
My observation is that system preferences when closing the window does some rounding for newly set values, they differ slightly from when I set a new value in the open pane of the speech settings.

regards
Bernd

Re: get the current SpeechSpeed

Posted: Mon Aug 09, 2010 7:27 pm
by jmburnod
Hi,

I tested the new version of getSpeechRateASII.rev

1. powerbook g4 10.4.2 minimum 1, middle 200, max 400
I readed on the revdictionary :
"The wordsPerMinute is an integer between 1 and 300"

2. Intel duo Core 10.5.6 always 1.0

If rev can "set" then it must can "get". Isn't it ?

best

Jean-Marc

Re: get the current SpeechSpeed

Posted: Mon Aug 09, 2010 8:50 pm
by bn
jmburnod wrote:I tested the new version of getSpeechRateASII.rev

1. powerbook g4 10.4.2 minimum 1, middle 200, max 400
I readed on the revdictionary :
"The wordsPerMinute is an integer between 1 and 300"
These are the correct values. Internaly the system preferences "speech" the slider has values from 1 to 401, 200 being the middle value.

What worries me is the 1.0 you get on the duo core 10.5.6.
I have no idea why.
I tested on one iMac with 10.4.11, one power mac with 10.5.9 and a MacBook Pro with 10.6.4.
They all worked.
I have no idea why you would get 1.0, actually you should not have in the disply 1.0 (in rev) since I truncate the number, did you use the previous version of getSpeechRateASIII.rev which would be getSpeechRateASII.rev?
Could you please make shure you tested with the new version: getSpeechRateASIII.rev (III) on the Intel duo Core? In that latest version there should not be a decimal point in the display. In your post from sunday you said:
2. Intel Core duo 10.5.6 : return 1.0
regards
Bernd

regards
Bernd