Object: SpVoice
AudioOutput Property
The AudioOutput property gets and sets the current audio output object used by the voice.
The AudioOutput property can be set with the object token for a standard Windows multi-media device. To use other types of devices, please see the Speech Telephony Application Guide.
Syntax
Set: | SpVoice.AudioOutput = SpObjectToken |
Get: | SpObjectToken = SpVoice.AudioOutput |
Parts
- SpVoice
- The owning object.
- SpObjectToken
-
Get: An SpObjectToken object that gets the current audio output.
Set: An SpObjectToken object that sets the audio output.
Remarks
When setting the value, if the object is Nothing then the default audio device will be used.
Example
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.
Note If the computer currently has only one audio output device, clicking Command1 will not change the entry in the list box.
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
EH:
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
EH:
If Err.Number Then ShowErrMsg
End Sub
Private Sub ShowAudioOutputs()
On Error GoTo EH
Dim strAudio As String
Dim strCurrentAudio As String
List1.Clear
Set T = V.AudioOutput 'Token for current audio output
strCurrentAudio = T.GetDescription 'Get description from token
'Show all available outputs; highlight the one in use
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
Next
EH:
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
End Sub