RapidWareTech / pyttsx

Cross-platform text-to-speech wrapper
Other
368 stars 134 forks source link

I can save the output of pyttsx to a wav file in windows, but the process suspended #15

Open hick opened 10 years ago

hick commented 10 years ago

sorry for I just have a little knowledge about both Python and win32 API.

but I had tried the old PYTTS package and some other code from google, and finnaly can save the wav file, by editing the pyttsx/drivers/sapi5.py as the following:

insert a line self._stream = win32com.client.Dispatch('SAPI.SpFileStream') after self._tts = win32com.client.Dispatch('SAPI.SPVoice') to create a file stream .

and in the function say , add some code around self._tts.Speak(unicode(text), 19) :

self._stream.Open("test.wav", 3) 
self._tts.AudioOutputStream = self._stream
self._tts.Speak(unicode(text), 19)

it worked, but, my python script never stopped, just suspended, I had try to edit the say function and runAndWait function, failed with my poor knowledge,

maybe somebody can help me? or maybe some other way to record the tts 's output to wav or mp3 files---I tried to record by pyaudio, but it always recorded the microphone directly.

hick commented 10 years ago

I had tried to Close the stream in function "say" after runAndWait like this, it did not work

    self._tts.Speak(unicode(text), 19)
    self._tts.runAndWait()   # also not work for self.runAndWait()
    self._stream.Close()  

I found the function runAndWait , but just did not know how to close

hick commented 10 years ago

I have found a ugly way to record in windows(tested in windows xp), you can see it in the https://github.com/hick/pyttsx

if the output wav file is not full, try to modify some code in pyttsx/drivers/sapi5.py, just search this string: "if you wav file is not full, change 5 in the line below to small number for more time to loop"

by Hick