[Tutor] File Stream Assignment?

FT chester_lab at fltg.net
Sat Jun 21 11:34:26 CEST 2008




Alan Gauld Wrote:
"FT" <chester_lab at fltg.net> wrote

Caveat: I know nothing about MS SAPI.

> The following code illustrates how to speak a text file
> in a specific voice in Visual Basic. This example
Notice this says nothing about writing to a file.

> Dim FileName As String
> Dim FileStream As New SpFileStream
> Dim Voice As  SpVoice
> 'Create SAPI voice
And the code nowhere writes to a file. The only file
mentioned is the one read.

No, it calls the Speak method to speak it.
It never saves anything so far as I can see.

> did above I get only the data spoken and the file with 0 bytes in
> it.

I'm not sure which file has zero bytes. I hope not the one being
spoken!
But it sounds to me like your code is doing what the VB code does.

I'm confused about why you think it should be saving anything?

--
Alan Gauld
Author of the Learn to Program web site


Alan,

    Sorry about that, I copied over to quickly and actually took the example
just below the one I wanted. This is the example and of course I looked back
after sending it and discovered the very same conclusion you came up with.

    Below is the one I am talking about. How to connect the audio stream to
an open file for writing is what I am trying to do.

Speak to a wav file in automation
The following example is written in Visual Basic. It has the same
functionality as
the above in C++. After the creation of an SpFileStream object, a default
format,
SAFT22kHz16BitMono, is assigned to the object so that user does not need to
explicitly
assign a wav format to it unless a specific wav format is needed. In this
example,
ISpeechFileStream.Open creates a wav file, ttstemp.wav, and binds the
FileStream
to the file. The third parameter of ISpeechFileStream.Open is the Boolean,
DoEvents.
The default of this parameter is set to False. However, the user should
always set
it to True to display SAPI events while playing back the wav file. If the
parameter
is set to False, no engine events will be stored in the file, resulting in
that no
engine events will be fired during the wav file play back.
Dim FileName As String
Dim FileStream As New SpFileStream
Dim Voice As  SpVoice
'Create a  SAPI voice
Set Voice = New SpVoice
'The output audio data will be saved to ttstemp.wav file
FileName = "c:\ttstemp.wav"
'Create a file; set DoEvents=True so TTS events will be saved to the file
FileStream.Open FileName, SSFMCreateForWrite, True
'Set the output to the FileStream
Set Voice.AudioOutputStream = FileStream
'Speak the text
Voice.Speak "hello world"
'Close the Stream
FileStream.Close
'Release the objects
Set FileStream = Nothing
Set Voice = Nothing



More information about the Tutor mailing list