SpVoice GetAudioOutputs method (SAPI 5.4)

Microsoft Speech API 5.4

Object: SpVoice

GetAudioOutputs Method

The GetAudioOutputs method returns a selection of available audio output tokens.

See Object Tokens and Registry Settings White Paper for a list of SAPI 5-defined attributes.

     [RequiredAttributes As String = ""],
     [OptionalAttributes As String = ""]
) As ISpeechObjectTokens


  • RequiredAttributes
    [Optional] Specifies the RequiredAttributes. To be returned by GetAudioOutputs, audio output tokens must contain all of the specific required attributes. If no tokens match the selection, the selection returned will not contain any elements. By default, no attributes are required and so the method returns all the tokens discovered.
  • OptionalAttributes
    [Optional] Specifies the OptionalAttributes. Returned tokens containing the RequiredAttributes are sorted by OptionalAttributes. If OptionalAttributes is specified, the tokens are listed with the OptionalAttributes first. By default, no attribute is specified and the list returned from the speech configuration database is in the order that attributes were discovered.

Return Value

An ISpeechObjectTokens collection containing the selected outputs.


The format of selection criteria may either be Value or "Attribute = Value". Values may be excluded by "Attribute != Value".


The following Visual Basic form code demonstrates the use of the GetAudioOutputs method and the AudioOutput property. To run this code, create a form with the following controls:

  • A command button called Command1
  • A list box called List1

Paste this code into the Declarations section of the form.

The Form_Load procedure creates an SpVoice object and calls a subroutine called ShowAudioOutputs. This subroutine uses the GetAudioOutputs method to select all available output devices and adds each device to the list box. The string (Current) is appended to the current audio device name.

Select a device in the list box and then click Command1. The Command1_Click procedure resets the voice's AudioOutput property to the device selected in the list box, and calls the ShowAudioOutputs subroutine, which will display the device selected as the current audio output.

Option Explicit

Private V As SpeechLib.SpVoice
Private T As SpeechLib.SpObjectToken

Private Sub Form_Load()
    On Error GoTo EH
    Set V = New SpVoice
    Call ShowAudioOutputs

    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command1_Click()
    On Error GoTo EH

    If List1.ListIndex > -1 Then
        Set V.AudioOutput = V.GetAudioOutputs().Item(List1.ListIndex)
        Call ShowAudioOutputs
    End If

    If Err.Number Then ShowErrMsg
End Sub

Private Sub ShowAudioOutputs()
    On Error GoTo EH

    Dim strAudio As String
    Dim strCurrentAudio As String

    Set T = V.AudioOutput               'Token for current audio output
    strCurrentAudio = T.GetDescription  'Get description from token

    For Each T In V.GetAudioOutputs
        strAudio = T.GetDescription     'Get description from token
        If strAudio = strCurrentAudio Then
            strAudio = strAudio & " (Current)"  'Show current device
        End If
        List1.AddItem strAudio          'Add description to list box

    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