Object: SpVoice
SpeakStream Method
The Speakstream method initiates speaking of a sound file by the voice.
SpVoice.SpeakStream(
Stream As ISpeechBaseStream,
[Flags As SpeechVoiceSpeakFlags = SVSFDefault]
) As Long
Parameters
- Stream
- Specifies an ISpeechBaseStream object containing the stream.
- Flags
- [Optional] Specifies the Flags. Default value is SVSFDefault.
Return Value
A Long variable containing the stream number. When a voice enqueues more than one stream by speaking asynchronously, the stream number is necessary to associate events with the appropriate stream.
Example
The following code snippet demonstrates the use of the SpeakStream method. To run this code, create a form with the following control:
- A command button called Command1
Paste this code into the Declarations section of the form.
The Form_Load procedure creates a male and a female voice. The Command1_Click procedure causes the female voice to speak text into a file, and the male voice to play that file using the SpeakStream method.
Option Explicit
Private M As SpeechLib.SpVoice 'M is a male voice
Private F As SpeechLib.SpVoice 'F is a female voice
Private S As SpeechLib.SpFileStream
Private Sub Command1_Click()
'Build a local file path and open it as a stream
Set S = New SpFileStream
Call S.Open("C:\SpeakStream.wav", SSFMCreateForWrite, False)
'Female voice speaks into the file stream and creates a WAV file
Set F.AudioOutputStream = S
F.Speak "cee : \ speak stream dot wave", SVSFNLPSpeakPunc
S.Close
'Male voice speaks female voice's stream
Call S.Open("C:\SpeakStream.wav", , False)
M.Speak "i will now demonstrate the speak stream method."
M.SpeakStream S
M.Speak "that sounded like " & F.Voice.GetDescription & ", but it was me."
End Sub
Private Sub Form_Load()
'Create voices
Set F = New SpVoice
Set F.Voice = F.GetVoices("gender=female").Item(0)
Set M = New SpVoice
Set M.Voice = M.GetVoices("gender=male").Item(0)
End Sub