[python-win32] possible to save the output of TTS to a WAV file?

Thomas Heller theller at ctypes.org
Fri Mar 7 22:11:26 CET 2008


Alec Bennett schrieb:
> I'm trying to save the output of some TTS to a sound file, is this possible?
> 
> Here's how I'm doing the TTS, though am certainly open to other methods:
> 
> import pythoncom, win32com
> import win32api, win32com.client
> pythoncom.CoInitialize ()
> 
> s = win32com.client.Dispatch("SAPI.SpVoice")
> s.Speak("hi there")
> 
> Thanks for any help.

In comtypes, this code does 'speak to a file':

        engine = CreateObject("SAPI.SpVoice")
        stream = CreateObject("SAPI.SpFileStream")
        from comtypes.gen import SpeechLib

        stream.Open(fname, SpeechLib.SSFMCreateForWrite)

        engine.AudioOutputStream = stream
        engine.speak("Hello, World", 0)
        stream.Close()

Should be trivial to convert it to pywin32.

Thomas



More information about the python-win32 mailing list