[Tutor] File Stream Assignment?

FT chester_lab at fltg.net
Sat Jun 21 11:44:27 CEST 2008


Alan,

    This is what I wrote in python. The onlyu thing I did not do is a
declaration of a filestream as the VB example does. I get no errors, just
the Speak method just speaks. The saved file has no data, 0 Bytes.
    Now the note they mentioned was the True flag and I inserted that.

import Sapi5, time, os
av = Sapi5.SynthDriver()
av.init()    #AN ASSIGNMENT I COULD PLACE IN FIRST CALL AND CALL THE METHOD
.Create()
SYNC = av._sync
ASYNC = av._async
PURGE = av._purge
ISFILE = av._is_filename
XML = av._xml
NOT_XML = av._not_xml
PERSIST = av._persist_xml
PUNC = av._punc
WAIT = av._wait

av.Speak("Hello!")
av.Speak( "I am speaking in the default voice!")
av.Speak( "Number of voices is: %d" % av.getVoiceCount())
av.Speak( "Hello! Now saying the punctuation in this sentence.", PUNC)
time.sleep(.5)

file4tts = open('test.wav', 'w', True)
av.AudioOutputStream = file4tts
av.Speak( "Hello World!", ASYNC)
file4tts.close

Microsoft Example:
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