Jump to content

SAPI SpVoice


Recommended Posts

1st. found only had Microsoft Sam installed

After some research finally have 4 voices installed

Can retrieve which voices are installed, but to can't figure out how to change the voice for the speak function without writing to a file using WScript

Any Help would be greatly appreciated

Here's the short code to get the voices and the results

Dim $voic = ObjCreate("SAPI.SpVoice")
Dim $SOTokens = $Voic.GetVoices('', '')
For $Token In $SOTokens
        ConsoleWrite($Token.GetDescription & @LF)
Next

$voic = ""

>Running: (3.1.1.51):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Documents and Settings\Gary\My Documents\test4.au3" 

Microsoft Mary

Microsoft Mike

Microsoft Sam

Sample TTS Voice

>AutoIT3.exe ended.

>Exit code: 0    Time: 1.265

Gary Edited by gafrost

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

1st. found only had Microsoft Sam installed

After some research finally have 4 voices installed

Can retrieve which voices are installed, but to can't figure out how to change the voice for the speak function without writing to a file using WScript

you should be able to set the voice with this command: $voic.voice = $voic.Getvoices("","").item(0)

However, on my system this throws a COM error ("member not found"), although I believe that the syntax is O.K. (see SAPI help file)

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

Had already tried that

_TalkOBJ('This is auto it beta speaking.', 1)

;voice params:
;
;1 - Microsoft Mary
;2 - Microsoft Mike
;3 - Microsoft Sam
;4 - Sample TTS Voice

Func _TalkOBJ($s_text, $s_voice = 3)
    Local $o_speech = ObjCreate ("SAPI.SpVoice")
    Local $i = 0, $voice
    Dim $SOTokens = $o_speech.GetVoices('', '')
    For $voice In $SOTokens
        ConsoleWrite($s_voice & ", " & $i & @LF)
        Select
            Case $s_voice == 1 And $i == 0
                ConsoleWrite($voice.GetDescription & @LF)
                $o_speech.Voice = $o_speech.GetVoices("","").Item(0)
;~              $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)
                $o_speech.Speak ($s_text)
                ExitLoop
            Case $s_voice == 2 And $i == 1
                ConsoleWrite($voice.GetDescription & @LF)
                $o_speech.Voice = $o_speech.GetVoices("","").Item(1)
;~              $o_speech.Voice = $voice.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)
                $o_speech.Speak ($s_text)
                ExitLoop
            Case $s_voice == 3 And $i == 2
                ConsoleWrite($voice.GetDescription & @LF)
                $o_speech.Voice = $o_speech.GetVoices("","").Item(2)
;~              $o_speech.Voice = $voice.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)
                $o_speech.Speak ($s_text)
                ExitLoop
            Case $s_voice == 4 And $i == 3
                ConsoleWrite($voice.GetDescription & @LF)
                $o_speech.Voice = $o_speech.GetVoices("","").Item(3)
;~              $o_speech.Voice = $voice.GetVoices("Name=Sample TTS Voice", "Language=409").Item(0)
                $o_speech.Speak ($s_text)
                ExitLoop
        EndSelect
        $i = $i + 1 
    Next
    $o_speech = ""
EndFunc  ;==>_TalkOBJ

Throws an error

>Running: (3.1.1.51):C:\Program Files\AutoIt3\beta\autoit3.exe "C:\Documents and Settings\Gary\My Documents\test4.au3" 

1, 0

Microsoft Mary

C:\Documents and Settings\Gary\My Documents\test4.au3 (27) : ==> The requested action with this object has failed.:

$o_speech.Voice = $o_speech.GetVoices("","").item(0)

$o_speech.Voice = $o_speech.GetVoices("","").item(0)^ ERROR

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

Throws an error

Yup, same on my system. If you catch the the COM error, you will get the error message I mentioned in my first post ("member not found"). Whatever that means...

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 

; Performing a deliberate failure here (object does not exist)
$fault1=$ColProcessors.item(1) 

Exit 


; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
               "Number is: " & $HexNumber & @CRLF & _
               "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

Cheers

Kurt

__________________________________________________________(l)user: Hey admin slave, how can I recover my deleted files?admin: No problem, there is a nice tool. It's called rm, like recovery method. Make sure to call it with the "recover fast" option like this: rm -rf *

Link to comment
Share on other sites

This now works with latest beta 3.1.1.53

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 

_TalkOBJ('This is auto it beta speaking.', 1)
_TalkOBJ('This is auto it beta speaking.', 2)
_TalkOBJ('This is auto it beta speaking.', 3)

;voice params:
;
;1 - Microsoft Mary
;1 - Microsoft Sam
;3 - Microsoft Mike

Func _TalkOBJ($s_text, $s_voice = 3)
    Local $o_speech = ObjCreate ("SAPI.SpVoice")
        Select
            Case $s_voice == 1
                $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)
            Case $s_voice == 2
                $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)
            Case $s_voice == 3
                $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)
        EndSelect
    $o_speech.Speak ($s_text)
    $o_speech = ""
EndFunc  ;==>_TalkOBJ

; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
               "Number is: " & $HexNumber & @CRLF & _
               "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

SciTE for AutoItDirections for Submitting Standard UDFs

 

Don't argue with an idiot; people watching may not be able to tell the difference.

 

Link to comment
Share on other sites

sweet. i made this:

Local $o_speech = ObjCreate ("SAPI.SpVoice")

For $i = 0 To $o_speech.GetVoices().Count() - 1
    
    $voice = $o_speech.GetVoices().Item($i)
    
    $o_speech.Voice = $voice

    $o_speech.Speak ('I am a ' & $voice.GetAttribute("Gender") & ' and my name is ' & $voice.GetAttribute("Name") & '. <rate speed="6">I can talk really fast</rate> <rate speed="-9">but also very slowly</rate>. By the way, i <pitch middle="50">can also talk high</pitch> <pitch middle="-50">and talk low.</pitch> Cool.', 8)

Next

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

This now works with latest beta 3.1.1.53

<{POST_SNAPBACK}>

********** As ALWAYS, Your timing is Impecable

If $Vc = "on" Then

$a=GUIGetCursorInfo()

If $a[4] = $Icon_1 then $o_speech.Speak ("1",8)

If $a[4] = $Icon_2 then $o_speech.Speak ("2",8)

..............and so on

I was looking for a way to do this... and low and behold along comes gafrost AGAIN!!!!.. and wOuter

thx

??Still don't have the fix for the curve cut-out on the last pic/shape??

thx

8)

Edited by Valuater

NEWHeader1.png

Link to comment
Share on other sites

  • 7 months later...

This now works with latest beta 3.1.1.53

$oMyError = ObjEvent("AutoIt.Error","MyErrFunc"); Install a custom error handler 

_TalkOBJ('This is auto it beta speaking.', 1)
_TalkOBJ('This is auto it beta speaking.', 2)
_TalkOBJ('This is auto it beta speaking.', 3)

;voice params:
;
;1 - Microsoft Mary
;1 - Microsoft Sam
;3 - Microsoft Mike

Func _TalkOBJ($s_text, $s_voice = 3)
    Local $o_speech = ObjCreate ("SAPI.SpVoice")
        Select
            Case $s_voice == 1
                $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mary", "Language=409").Item(0)
            Case $s_voice == 2
                $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Mike", "Language=409").Item(0)
            Case $s_voice == 3
                $o_speech.Voice = $o_speech.GetVoices("Name=Microsoft Sam", "Language=409").Item(0)
        EndSelect
    $o_speech.Speak ($s_text)
    $o_speech = ""
EndFunc ;==>_TalkOBJ

; This is my custom error handler 
Func MyErrFunc() 
   $HexNumber=hex($oMyError.number,8) 
   Msgbox(0,"","We intercepted a COM Error !" & @CRLF & _
               "Number is: " & $HexNumber & @CRLF & _
               "Windescription is: " & $oMyError.windescription ) 

   SetError(1); something to check for when this function returns 
Endfunc

Latest Beta (3.1.1.108) doesn't seem to work with this code. I get COM errors:

We intercepted a COM Error !

Number is: 80020005

Windescription is: Type mismatch

“Efficiency is doing things right; effectiveness is doing the right things.”-Peter F. Drucker

Link to comment
Share on other sites

Works with 3.1.1.109

Can't keep up with these guys! I just installed a couple of days ago! :">

Spoke too soon... same problem with 3.1.1.109 and 3.1.1.110 Any ideas?

Edited by thefluxster

“Efficiency is doing things right; effectiveness is doing the right things.”-Peter F. Drucker

Link to comment
Share on other sites

change all of these to 3... because you do not have other voices installed

_TalkOBJ('This is auto it beta speaking.', 3)

_TalkOBJ('This is auto it beta speaking.', 3)

_TalkOBJ('This is auto it beta speaking.', 3)

8)

I'll check on that and get back to you.

“Efficiency is doing things right; effectiveness is doing the right things.”-Peter F. Drucker

Link to comment
Share on other sites

Sorry I didn't reply sooner - left work and forgot about it when I got home. Yes, it is because I don't have all the voices installed. It worked fine on my friends computer. Thanks a million.

BTW, for anyone interested, "Microsoft Anna" is probably the best voice emulation you can use for this. If you slow it down just a bit, it actually sounds like a real person and does a better job pronouncing odd bits.

My two cents.

“Efficiency is doing things right; effectiveness is doing the right things.”-Peter F. Drucker

Link to comment
Share on other sites

Sorry I didn't reply sooner - left work and forgot about it when I got home. Yes, it is because I don't have all the voices installed. It worked fine on my friends computer. Thanks a million.

BTW, for anyone interested, "Microsoft Anna" is probably the best voice emulation you can use for this. If you slow it down just a bit, it actually sounds like a real person and does a better job pronouncing odd bits.

My two cents.

I understand Microsoft Anna is for Windows Vista... Can we get it for Windows Xp

??

8)

NEWHeader1.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...