Open 2goodgabe opened 6 months ago
It has to do with your file format, switch it to .wav
or even better .aiff
instead of .mp3
Long story: This library uses NSSpeechSynthesizer
(deprecated) for macOS to save the audio into a file
By default, it synthesizes the text into an AIFF file format, per the docs that's the only format it supports.
Since both .wav
and .aiff
formats follow the same type of encoding (with difference in file size though), you may most likely be able to generate .wav
but NSSpeechSynthesizer
DOES NOT support or recognize mp3 files
Remember NSSpeechSynthesizer
class in macOS is specifically designed for speech synthesis and text-to-speech functionality. It is not intended for MP3 files.
With that said, the current library has many short comings specific to latest versions of macOS. I had multiple PRs that went stale. I tried to reach out to Natesh (the author) several times to get my PR merged. Due to lack of response, I created a spin off library py3-tts with fixes for all the things macOS decided to change after Catalina
So far, the major issues that's been fixed in py3-tts
are:
KeyError
in case of missing voice attributesNSSpeechDriver
Hope this helps
Hi! I'm using pyttsx3 in one of my projects, and I'm testing the library in a separate python file. More specifically, I'm trying to save the speech as an mp3 file. This is what I have.
import pyttsx3 as tts
engine = tts.init() engine.setProperty('rate', 180) engine.setProperty('volume', 0.9)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[30].id)
engine.save_to_file("Hello. This is a test.", 'test.mp3') engine.runAndWait()
What I've noticed, however, is that nothing ever actually happens. The speech works perfectly fine; it's saving it as a file that's an issue. I don't get any errors while this script is running; it just runs forever :(
Any help is appreciated!
I'm on MacOS Sonoma 14.0