1

I want to convert text to speech offline using pyttsx3 and I want to save the output to an audio file.

I have seen this question and the first answer would be exactly what I need. I just couldn't get it to function.

When running this:

import pyttsx3
tts = pyttsx3.init()
tts.setProperty('voice', tts.getProperty('voice')[1])
tts.save_to_file("What an amazing day today! I'm gonna go for a swim.", "./filename.mp3")
tts.runAndWait()

It doesn't give me an error, it just doesn't output anything and doesn't create a file. The rest of my could should be correct because if I do:

import pyttsx3
tts = pyttsx3.init()
tts.setProperty('voice', tts.getProperty('voice')[1])
tts.say("What an amazing day today! I'm gonna go for a swim.")
tts.runAndWait()

everything works just fine.

I expected the top bit of code to output to a file, instead, it does nothing. I am running windows 10, latest update. Python 3.7.4 32-bit and pyttsx3 version 2.71 Thank you for your help!

Oh, and one more thing, I know the output of save_to_file is most likely not mp3, but I didn't know what it would be and I needed it in mp3 for my next step, so that's what I called it. If I try to set the file extension to something else, it runs just the same.

Zegevlier
  • 63
  • 1
  • 7

1 Answers1

0

save_to_file is one of the function in pyttsx3.engine.Engine class however it is not tested yet and does not provide an output. if you run it from python command line it will give you Attribute error saying str object has not attribute proxy.

which is due to driverProxy in ivar self.proxy and i do not think any of the driverName would resolve it as of now since this is actually calling waekref.proxy and i think this is the reason save_to_file is never mentioned in documentation like other functions.

I have posted this error to github and waiting for an answer.lets Wait till then :-)