Here is my code:
mp3_path = filedialog.asksaveasfile(filetypes=(("MP3 files", "*.mp3"),
("All files", "*.*"))) # User prompt to select a path.
engine = pyttsx3.init() # A pyttsx3 object
engine.setProperty('rate', 100) # Set speed to speed given in entry
engine.save_to_file('Hi and welcome to my audiobook.', mp3_path) # Save mp3 to specified path
engine.runAndWait()
Now, when I try to save the MP3, it doesn't work and the mp3 is empty. I copied and pasted the doc example but it still doesn't work.
I am using MacOS so installing espeak-ng is not needed too.
I didn't figure out the problem, so I just used gTTS. Overall, gTTS is easier to use, BUT with pyttsx3 allows you to customize speed and other things unlike gTTS. Here is the code I used:
mp3_path = filedialog.asksaveasfilename(filetypes=(("MP3 files", "*.mp3"),
("All files", "*.*"))) # User prompt to select a path.
# Use gTTS library to manage text to speech conversion
tts = gTTS(text=text, lang='en') # gTTS Object
tts.save(mp3_path) # Save gTTS object to specified path
As visible using gTTS cut the code by a lot but I am not defining speed.