SpAudioFormat Type Property (Microsoft Speech Platform)

Microsoft Speech Platform SDK 11

Microsoft Speech Platform

Object: SpAudioFormat

Type Property

The Type property gets and sets the speech audio format as a SpeechAudioFormatType.

Most applications using standard audio formats should use Type to set and retrieve formats.


Syntax

Set: SpAudioFormat.Type = SpeechAudioFormatType
Get: SpeechAudioFormatType = SpAudioFormat.Type

Parts

SpAudioFormat
The owning object.
SpeechAudioFormatType
Set: A SpeechAudioFormatType object that sets the property.
Get: A SpeechAudioFormatType object that gets the property.

Example

The following Visual Basic form code demonstrates the use of the Type and Guid properties. To run this code, create a form with the following controls:

  • Two command buttons called Command1 and Command2

Paste this code into the Declarations section of the form.

The Command1 procedure creates a token category object and sets it to the category of audio inputs, selects a token for the first MMSys resource, and instantiates an SpMMAudioIn object with the token's CreateInstance method. The code then creates an SpAudioFormat object from the SpMMAudioIn object, and changes the Type property of the SpAudioFormat object. Finally, the code sets the Format property of the SpMMAudioIn object with the SpAudioFormat object.

The Command2 procedure performs the same series of operations with audio outputs instead of audio inputs.


Option Explicit

Dim C As SpeechLib.SpObjectTokenCategory
Dim T As SpeechLib.SpObjectToken

Dim I As SpeechLib.SpMMAudioIn
Dim O As SpeechLib.SpMMAudioOut

Dim F As SpeechLib.SpAudioFormat

Private Sub Command1_Click()
    On Error GoTo EH

    Debug.Print
    Debug.Print "MMSys AudioIn"
    Debug.Print

    'Set category object to audio input resources
    Set C = New SpObjectTokenCategory
    C.SetId SpeechCategoryAudioIn

    'Set token object to first MMSys input resource
    Set T = C.EnumerateTokens("Technology=MMSys").Item(0)
    Debug.Print "First device: " & T.GetDescription

    'Create an SpMMAudioIn object from the token,
    'and show some of its properties
    Set I = T.CreateInstance()
    Debug.Print "DeviceId: " & I.DeviceId
    Debug.Print "original Audio Format:" & I.Format.Type

    'Create an Audio Format object from resource
    'If Audio Format's Type is standard, then change it
    Set F = I.Format
    If F.Type = SAFT22kHz16BitMono Then
        F.Type = SAFT11kHz16BitMono
    End If

    'Set Audioinput's format with changed format object
    Set I.Format = F
    Debug.Print " changed Audio Format:" & I.Format.Type
    Debug.Print "Guid:" & F.Guid

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command2_Click()
    On Error GoTo EH

    Debug.Print
    Debug.Print "MMSys AudioOut"
    Debug.Print
    Set C = New SpObjectTokenCategory
    C.SetId SpeechCategoryAudioOut
    Set T = C.EnumerateTokens("Technology=MMSys").Item(0)
    Debug.Print "First device: " & T.GetDescription
    Set O = T.CreateInstance()
    Debug.Print "DeviceId: " & O.DeviceId
    Debug.Print "original Audio Format:" & O.Format.Type
    Set F = O.Format
    If F.Type = SAFT22kHz16BitMono Then
        F.Type = SAFT11kHz16BitMono
    End If
    Set O.Format = F
    Debug.Print " changed Audio Format:" & O.Format.Type
    Debug.Print "Guid:" & F.Guid

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