Jump to content

_Talk this function speaks text to you


erifash
 Share

Recommended Posts

Thanks to El-Trucha for making a _Talk() function. I have modified it so that instead of exporting VBScript, it uses objects (requires latest beta). I tried to make the voices change but, no luck. Here's the code (with example):

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

Func _TalkOBJ($s_text)
  Local $o_speech = ObjCreate("SAPI.SpVoice")
  $o_speech.Speak($s_text)
  $o_speech = ""
EndFunc

Any help with the different voices? I checked MSDN and I think I should use $o_speech.SetVoice() but when I try to, it doesn't work. I think I'm getting the syntax wrong.

Link to comment
Share on other sites

Link to comment
Share on other sites

But, in the topic you directed me to, Green Lantern asks...

How can you change the voice in AutoIt with COM?

<{POST_SNAPBACK}>

...and no one replied. So, how can you change the voice in Autoit with COM? :) I would be very glad if someone answered this because all I get is the "action with this object failed" error.
Link to comment
Share on other sites

from roger:

' Declaring variable to hold SAPI object.
Dim voic

' Creating SAPI object using spvoice.
Set voic = Wscript.CreateObject("SAPI.SpVoice")

' If you want to change the voice then uncomment any of the following 4 lines.

'Set voic.voice = voic.GetVoices("Name=Microsoft mary", "Language=409").Item(0)
'Set voic.voice = voic.GetVoices("Name=Microsoft mike", "Language=409").Item(0)
'Set voic.voice = voic.GetVoices("Name=Microsoft sam", "Language=409").Item(0)
'Set voic.voice = voic.GetVoices("Name=crystal16", "Language=409").Item(0)

' you can set other parameters and properties like voice pitch, speed etc.  

' Using speak function of SpVoice to speak a string.
voic.Speak("Welcome To My First Speech Enabled ASP Page, Have a nice day!")

' Destroying SAPI.spvoice object.
Set voic = nothing

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

I've never used COM before and came out with this? It doesn't work, I get an error, try it.

;Declaring variable to hold SAPI object.
Dim $voic

;Creating SAPI object using spvoice.
$voic = ObjCreate("SAPI.SpVoice")

;If you want to change the voice then uncomment any of the following 4 lines.

$voic.voice = $voic.GetVoices("Name=Microsoft mary", "Language=409").Item(0)
;Set voic.voice = voic.GetVoices("Name=Microsoft mike", "Language=409").Item(0)
;Set voic.voice = voic.GetVoices("Name=Microsoft sam", "Language=409").Item(0)
;Set voic.voice = voic.GetVoices("Name=crystal16", "Language=409").Item(0)

;you can set other parameters and properties like voice pitch, speed etc.  

;Using speak function of SpVoice to speak a string.
$voic.Speak("Welcome To My First Speech Enabled ASP Page, Have a nice day!")

;Destroying SAPI.spvoice object.
$voic = ""

Remeber I've never used COM before...

FootbaG
Link to comment
Share on other sites

i think you need to use tokens to set it.

for ex. you can use tokens to get all the voices.

so i asume you should pass a token to the "set voice" func.

dim $voic = ObjCreate("SAPI.SpVoice")

For $Token In $Voic.GetVoices('', '')
        ConsoleWrite($token.GetDescription & @LF)
Next

$voic = ""

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

w0uter: Exactly what msdn said about the tokens thing, except I am a COM noob and didn't understand it.

layer: I tried that idea and it didn't work. I dug further into msdn and it said I need to use $o_speech.SetVoice() but when I try and do that it won't work. I might be getting the syntax wrong. :)

EDIT: I thought it would help to give you my failed attempt.

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

;voice params:
;
;1 - Microsoft Sam
;2 - Microsoft Mary
;3 - Microsoft Mike 
;4 - Crystal16 (if installed)

Func _TalkOBJ($s_text, $s_voice = 1)
  Local $o_speech = ObjCreate("SAPI.SpVoice")
  If $s_voice = 1 Then $o_speech.voice = $o_speech.GetVoices("Name=Microsoft sam", "Language=409").Item(0)
  If $s_voice = 2 Then $o_speech.voice = $o_speech.GetVoices("Name=Microsoft mary", "Language=409").Item(0)
  If $s_voice = 3 Then $o_speech.voice = $o_speech.GetVoices("Name=Microsoft mike", "Language=409").Item(0)
  If $s_voice = 4 Then $o_speech.voice = $o_speech.GetVoices("Name=crystal16", "Language=409").Item(0)
  $o_speech.Speak($s_text)
  $o_speech = ""
EndFunc
Edited by erifash
Link to comment
Share on other sites

  • 4 months later...

Yes the voice addition would be nice.

Hrm.. Sven where might you be lurking? B)

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

nice original scipt

wish we could get the voice selection to work

8)

Here is something I picked up in the forums a while back

$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

I have no idea who wrote it but it was not me.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

Hmmm... It looks like it should work but it doesn't on this computer because I only have Microsoft Sam. Can anyone else test this out?

Link to comment
Share on other sites

Hmmm... It looks like it should work but it doesn't on this computer because I only have Microsoft Sam. Can anyone else test this out?

I downloaded speechsdk51 from microsoft so that i could use it. It is a 70Mb download.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

I downloaded speechsdk51 from microsoft so that i could use it. It is a 70Mb download.

I have yet to download and test, but here is the link to the SDK.

http://msdn.microsoft.com/library/en-us/SA...tml/Welcome.asp

JS

AutoIt Links

File-String Hash Plugin Updated! 04-02-2008 Plugins have been discontinued. I just found out.

ComputerGetInfo UDF's Updated! 11-23-2006

External Links

Vortex Revolutions Engineer / Inventor (Web, Desktop, and Mobile Applications, Hardware Gizmos, Consulting, and more)

Link to comment
Share on other sites

Here is something I picked up in the forums a while back

$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

I have no idea who wrote it but it was not me.

Looks like the one I did a long time ago.

Edit: yep even has the same type-o in it.

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

Ok, I downloaded and installed SAPI 5.1 and now this function I posted earlier works:

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

;voice params:
;
;1 - Microsoft Sam
;2 - Microsoft Mary
;3 - Microsoft Mike 
;4 - Crystal16 (if installed)

Func _TalkOBJ($s_text, $s_voice = 1)
    Local $o_speech = ObjCreate("SAPI.SpVoice")
    If $s_voice = 1 Then $o_speech.voice = $o_speech.GetVoices("Name=Microsoft sam", "Language=409").Item(0)
    If $s_voice = 2 Then $o_speech.voice = $o_speech.GetVoices("Name=Microsoft mary", "Language=409").Item(0)
    If $s_voice = 3 Then $o_speech.voice = $o_speech.GetVoices("Name=Microsoft mike", "Language=409").Item(0)
    If $s_voice = 4 Then $o_speech.voice = $o_speech.GetVoices("Name=crystal16", "Language=409").Item(0)
    $o_speech.Speak($s_text)
    $o_speech = ""
EndFunc

Thanks!

Link to comment
Share on other sites

Looks like the one I did a long time ago.

Edit: yep even has the same type-o in it.

Gary

You are more than welcome to the credit. I sometimes think that it would be best if people put their names at the top of their scripts so that it is easier to remember who did them.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

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...