[Tutor] File Stream Assignment?
FT
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.
||||Snip||||
I have no idea what you mean by this.
Where are you looking? This is a COM object which is in the MS
library.
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
suggests
you have succeeded in that already.
I'm confused about why you think it should be saving anything?
--
Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld
Hi Alan,
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
ALONE!
#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
OF
THE FILE NAME TO SAVE THE VOICE INTO AND THE TEXT DATA TO SPEAK
AND STORE
ONCE THE TEXT IS SPOKEN INTO THE FILE IT IS CLOSED AND THE
OBJECTS DESTROYED!"""
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)
stream.Close()
del tts4file
del stream
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: SAPI5.py
URL: <http://mail.python.org/pipermail/tutor/attachments/20080621/7e6f1e9f/attachment.txt>
More information about the Tutor
mailing list