Jump to content
Sign in to follow this  

SAPI Get Voices method

Recommended Posts

I know I am going to kick myself, but I really can't figure out how to translate this MSDN VB article into AutoIt. I want to be able to retrieve a list of all of the SAPI voices stored on a computer (e.g. Microsoft Sam) and allow the end-user to pick one to use with a larger app I wrote in AutoIt. Any help would be very much appreciated. Here is the VB script which pretty much does what I need:

The Form_Load procedure creates a voice object and displays the names of all available voices in the list box. Select a voice name in the list box and then click Command1. The Command1 procedure sets the voice object's Voice property to the selected name and causes the voice to speak its new name.

Option Explicit

Private V As SpeechLib.SpVoice
Private T As SpeechLib.ISpeechObjectToken

Private Sub Command1_Click()
    On Error GoTo EH

    If List1.ListIndex > -1 Then

        ' Set voice object to voice name selected in
        ' list box (new voice speaks its own name):
        Set V.Voice = V.GetVoices().Item(List1.ListIndex)
        V.Speak V.Voice.GetDescription

        MsgBox "Please select a voice from the list box."
    End If

    If Err.Number Then ShowErrMsg
End Sub

Private Sub Form_Load()
    On Error GoTo EH

    Dim strVoice As String

    Set V = New SpVoice

    'Get each token in the collection returned by GetVoices
    For Each T In V.GetVoices
        strVoice = T.GetDescription     'The token's name
        List1.AddItem strVoice          'Add to listbox

    If Err.Number Then ShowErrMsg
End Sub

Private Sub ShowErrMsg()

    ' Declare identifiers:
    Dim T As String

    T = "Desc: " & Err.Description & vbNewLine
    T = T & "Err #: " & Err.Number
    MsgBox T, vbExclamation, "Run-Time Error"

End Sub

Thank you again.

Share this post

Link to post
Share on other sites

$v = ObjCreate("Sapi.SpVoice")

For $voice in $v.GetVoices()
    ConsoleWrite($voice.GetDescription() & @CRLF)

Thank you so much Manadar. I messed up pretty badly. I totally forgot to use .GetDescription and used .Voice instead!!! Not thinking clearly. Of course, it is only so obvious now.

Thank you for the help. Now I'll just have to pass this through a combo or list box instead of a msgbox so the end-user can choose.


Sorry everyone that I posted this thread multiple times. I assure you it was an accident.

Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...