Export (0) Print
Expand All

SpFileStream Open Method (SAPI 5.3)

Speech API 5.3
Microsoft Speech API 5.3

Object: SpFileStream

Open Method


The Open method opens a filestream object for reading or writing.

SpFileStream.Open(
     FileName As String,
     [FileMode As SpeechStreamFileMode = SSFMOpenForRead],
     [DoEvents As Boolean = False]
)

Parameters

FileName
Specifies the FileName.
FileMode
[Optional] Specifies the FileMode. Default value is SSFMOpenForRead.
DoEvents
[Optional] When FileMode is SSFMCreateForWrite, DoEvents specifies whether playback of the resulting sound file will generate voice events. Default value is False.

Return Value

None.


Remarks

When the SpFileStream object is used with audio data, the FileMode parameter controls access strictly. That is, the FileMode parameter SFMOpenForRead prevents write access, and the FileMode parameter SSFMCreateForWrite prevents read access. When the SpFileStream object is used with text data, only the SFMOpenForRead FileMode parameter controls access strictly. The FileMode parameter SFMOpenForRead prevents write access, but the SSFMCreateForWrite parameter allows text data to be read as well as written.

When an SpVoice object creates an SPFileStream object, the engine may embed event data in the stream. In order to embed these events in the file stream, it must be opened for writing with the DoEvents parameter set to True. In order to receive these events when the stream is played back, it must be opened for reading with the DoEvents parameter set to True. Several other factors are involved. Please see SpVoice events for further details.

Example

The following Visual Basic form code demonstrates the use of a SpFileStream object to capture the output of a voice in a file. To run this code, create a form without any controls and paste this code into the Declarations section of the form.

The ISpeechPhraseElement code example demonstrates further use of the SpFileStream object. This example uses a text-to-speech voice to speak into an SpFileStream object, and uses the resulting file as the input for speech recognition.


Option Explicit

Private Sub Form_Load()
    On Error GoTo EH

    Dim objVOICE As SpeechLib.SpVoice
    Dim objFSTRM As SpeechLib.SpFileStream

    Set objVOICE = New SpVoice
    Set objFSTRM = New SpFileStream

    'Open file path as a stream
    Call objFSTRM.Open("c:\VoiceToFile.wav", SSFMCreateForWrite, False)

    'Set voice output to the stream and speak
    Set objVOICE.AudioOutputStream = objFSTRM
    objVOICE.Speak "cee : \ voice to file dot wave", SVSFNLPSpeakPunc

    Call objFSTRM.Close

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
Show:
© 2014 Microsoft