Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Collapse the table of content
Expand the table of content

SpCustomStream BaseStream Property (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3

Object: SpCustomStream

BaseStream Property

The BaseStream property gets and sets the base stream object in a custom stream.


Set: SpCustomStream.BaseStream = IUnknown
Get: IUnknown = SpCustomStream.BaseStream


The owning object.
Set: An Unknown variable that sets the base stream.
Get: An Unknown variable that gets the base stream.


The following Visual Basic form code demonstrates the use of the BaseStream property. To run this code, create a form with following control:

  • A command button called Command1

Paste this code into the Declarations section of the form.

The From_Load procedure creates two voice objects. The Command1 procedure creates a new custom stream, uses the CreateStreamOnHGlobal API to create a new genetic Istream object, and sets the Istream as the custom stream's BaseStream property. Finally, it uses the first voice to speak a phrase into the custom stream, and then plays back the custom stream audio with the second voice.

Option Explicit

Dim V1 As SpeechLib.SpVoice
Dim V2 As SpeechLib.SpVoice
Dim C As SpeechLib.SpCustomStream

Private Declare Function CreateStreamOnHGlobal Lib "Ole32.dll" ( _
    ByVal hGlobal As Any, ByVal fDeleteOnRelease As Boolean, _
    ByRef ppStream As IStream) As Long

Private Sub Command1_Click()
    Dim GeneticIstream As SpeechLib.IStream

    On Error GoTo EH

    'Create a genetic Istream object,
    'Use as custom stream's base stream
    CreateStreamOnHGlobal 0&;, True, GeneticIstream
    Set C = New SpCustomStream
    Set C.BaseStream = GeneticIstream

    'Set custom stream as voice's output stream
    'Make voice speak into the stream
    Set V1.AudioOutputStream = C
    V1.Speak "hello world"

    'Seek to beginning of stream, and speak stream
    C.Seek 0, SSSPTRelativeToStart
    V2.SpeakStream C

    If Err.Number Then ShowErrMsg
End Sub

Private Sub Form_Load()
    Set V1 = New SpVoice    'Creates a custom stream
    Set V2 = New SpVoice    'Speaks the custom stream
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
© 2015 Microsoft