[Tutor] File Stream Assignment?
chester_lab at fltg.net
Sat Jun 21 19:11:15 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 assumes
> a text file (ttstemp.txt) containing the text to be spoken
> already exists. ISpeechVoice.SpeakStream is used here
> to speak an SpFileStream that
> has been bound to the file.
I have no idea what you mean by this.
Where are you looking? This is a COM object which is in the MS
You will need to access it via PythonWin or ctypes or a Python
wrapper of some sort. But the fact you are getting it to speak
you have succeeded in that already.
I'm confused about why you think it should be saving anything?
Author of the Learn to Program web site
I did a search and I think it was about the 30'th search or more and
finally came out with the exact code. Interesting enough it was on the win32
site and a person did not want to use the working code for something more
like I was originally searching for, but it works.
Below is the method I placed it into. I use the same Create function but
the added feature is the lib and it was inside the Create assignment itself.
You were correct in it needed to be in the com stuff. I do not know all that
I need to know about this for there is so much to search and read to tie it
all together. So I do it one piece at a time. I also used the same naming
convention as the built in Speak method and I did not have to use C code to
get it runnhing, instead used the same imports I already had.
I attached the complete speech class module I am developing and the
methods I am using at the moment.
Here is the method:
from comtypes.client import CreateObject #NEEDED IF THIS METHOD IS A STAND
#SET AUDIO STREAM FOR OUTPUT TO A FILE!
def SpeakToWav(self, filename, text):
"""THIS METHOD ASSUMES THE IMPORT OF COMTYPES.CLIENT createObject SO
A VOICE AND FILE STREAM OBJECT ARE CREATED WITH THE PASSING IN
THE FILE NAME TO SAVE THE VOICE INTO AND THE TEXT DATA TO SPEAK
ONCE THE TEXT IS SPOKEN INTO THE FILE IT IS CLOSED AND THE
stream = CreateObject("SAPI.SpFileStream")
tts4file = CreateObject( 'sapi.SPVoice')
from comtypes.gen import SpeechLib
stream.Open( filename, SpeechLib.SSFMCreateForWrite)
tts4file.AudioOutputStream = stream
tts4file.Speak( text, 0)
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
More information about the Tutor