Offline Text To Speech synthesis for python
pyttsx3 is a text-to-speech conversion library in Python. Unlike alternative libraries, it works offline.
pip install pyttsx3If you get installation errors , make sure you first upgrade your wheel version using :
pip install --upgrade wheel
If you are on a Linux system and if the voice output is not working, then :
Install espeak-ng and libespeak1 as shown below:
sudo apt update && sudo apt install espeak-ng libespeak1import pyttsx3
engine = pyttsx3.init()
# For Mac, If you face error related to "pyobjc" when running the `init()` method :
# Install 9.0.1 version of pyobjc : "pip install pyobjc>=9.0.1"
engine.say("I will speak this text")
engine.runAndWait()Single line usage with speak function with default options
import pyttsx3
pyttsx3.speak("I will speak this text")Changing Voice , Rate and Volume :
…https://pyttsx3.readthedocs.io
| Linux | macOS | Windows | |
|---|---|---|---|
| AVSpeech | ✅︎ | ||
| eSpeak | ✅︎ | ✅︎ | ✅︎ |
| NSSpeechSynthesizer | ✅︎ | ||
| SAPI5 | ✅︎ |
[!NOTE]
- AVSpeechSynthesizer support is still experimental.
- NSSpeechSynthesizer is deprecated by Apple.
Feel free to wrap another text-to-speech engine for use with pyttsx3.
No open issues yet, or sync has not completed.