pyttsx3 is python library for text-to-speech. It works offline and is very easy to use. It s compatible with both Python 2 and 3. In this article I'll show you how to use for text-to-speech.
On windows, It uses follwing TTS engines as per OS:
- sapi5 – SAPI5 on Windows
- nsss – NSSpeechSynthesizer on Mac OS X
- espeak – eSpeak on every other platform
On windows, there are 2 voices, one is male and another is female. You can switch between them.
Let's install all required libraries first:
pip install pypiwin32
pip install -U pyttsx3==2.71
Now, here is how to write your first text-to-speech program:
import pyttsx3 # get an engine instance engine = pyttsx3.init() # Pass what we want it to say engine.say('Hello buddy. Welcome to HackersFriend') # run and wait method, it processes it engine.runAndWait()
After runnig this, you system should speak "Hello buddy. Welcome to HackersFriend".