Object: SpAudioFormat
Type: Hidden
GetWaveFormatEx Method
The GetWaveFormatEx method gets the audio format as an SpWaveFormatEx object.
Non-standard formats using wav files should use GetWaveFormatEx to retrieve formats.
SpAudioFormat.GetWaveFormatEx() As SpWaveFormatEx
Parameters
-
None.
Return Value
The GetWaveFormatEx method returns an SpWaveFormatEx variable.
Example
The following Visual Basic form code demonstrates the use of the GetWaveFormatEx and SetWaveFormatEx 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 an SpAudioFormat object and sets it to the audio format SAFT22kHz16BitStereo. It then gets the format object's SpWaveFormatEx object and displays the properties. The code then changes the format of the SpAudioFormat object to SAFT11kHz16BitMono, gets a new SpWaveFormatEx object and displays its properties again. Note that the SpWaveFormatEx properties have changed to reflect the new audio format.
The Command2 procedure creates an SpAudioFormat object and sets it to the audio format SAFT22kHz16BitStereo. It then gets the format object's SpWaveFormatEx object and displays the properties. The code then changes the properties of the SpWaveFormatEx object to match the SAFT11kHz16BitMono format and sets the format of the SpAudioFormat object with the SetWaveFormatEx method. Note that the SpAudioFormat object's Type property has changed to SAFT11kHz16BitMono to reflect the new SpWaveFormatEx properties.
Option Explicit
Dim F As SpeechLib.SpAudioFormat
Dim W As SpeechLib.SpWaveFormatEx
Private Sub Command1_Click()
On Error GoTo EH
'Create an empty SpAudioFormat object
'Set it to the default format
'Get its format in an SpWaveFormatEx object
Set F = New SpAudioFormat
F.Type = SAFT22kHz16BitStereo
Set W = F.GetWaveFormatEx
Debug.Print
Debug.Print "Default SpAudioFormat and SpWaveFormatEx"
Debug.Print "Format: SAFT22kHz16BitStereo"
Debug.Print "Format code: " & F.Type
Debug.Print "AvgBytesPerSec " & W.AvgBytesPerSec
Debug.Print "BitsPerSample " & W.BitsPerSample
Debug.Print "BlockAlign " & W.BlockAlign
Debug.Print "Channels " & W.Channels
Debug.Print "ExtraData " & W.ExtraData
Debug.Print "FormatTag " & W.FormatTag
Debug.Print "SamplesPerSec " & W.SamplesPerSec
'Give the SpAudioFormat object an audio type
'Get its format in an SpWaveFormatEx object
F.Type = SAFT11kHz16BitMono
Set W = F.GetWaveFormatEx
Debug.Print
Debug.Print "Changing SpAudioFormat changes SpWaveFormatEx"
Debug.Print "Format: SAFT11kHz16BitMono"
Debug.Print "Format code: " & F.Type
Debug.Print "AvgBytesPerSec " & W.AvgBytesPerSec
Debug.Print "BitsPerSample " & W.BitsPerSample
Debug.Print "BlockAlign " & W.BlockAlign
Debug.Print "Channels " & W.Channels
Debug.Print "ExtraData " & W.ExtraData
Debug.Print "FormatTag " & W.FormatTag
Debug.Print "SamplesPerSec " & W.SamplesPerSec
EH:
If Err.Number Then ShowErrMsg
End Sub
Private Sub Command2_Click()
On Error GoTo EH
'Create an empty SpAudioFormat object
'Set it to the default format
'Get its format in an SpWaveFormatEx object
Set F = New SpAudioFormat
F.Type = SAFT22kHz16BitStereo
Set W = F.GetWaveFormatEx
Debug.Print
Debug.Print "Default SpAudioFormat and SpWaveFormatEx:"
Debug.Print "Format: SAFT22kHz16BitStereo"
Debug.Print "Format code: " & F.Type
Debug.Print "AvgBytesPerSec " & W.AvgBytesPerSec
Debug.Print "BitsPerSample " & W.BitsPerSample
Debug.Print "BlockAlign " & W.BlockAlign
Debug.Print "Channels " & W.Channels
Debug.Print "ExtraData " & W.ExtraData
Debug.Print "FormatTag " & W.FormatTag
Debug.Print "SamplesPerSec " & W.SamplesPerSec
'Set SpWaveFormatEx properties as in SAFT11kHz16BitMono format;
'this will reset the SpAudioFormat Type.
Debug.Print
Debug.Print "Changing SpWaveFormatEx properties changes SpAudioFormat:"
W.AvgBytesPerSec = 22050
W.BitsPerSample = 16
W.BlockAlign = 2
W.Channels = 1
W.SamplesPerSec = 11025
Call F.SetWaveFormatEx(W)
Debug.Print "Format code: " & F.Type
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