pyttsx is a cross-platform text to speech library which is platform independent. The major advantage of using this library for text-to-speech conversion is that it works offline. However, pyttsx supports only Python 2.x. Hence, we will see pyttsx3 which is modified to work on both Python 2.x and Python 3.x with the same code.
Use this command for Installation:
pip install pyttsx3
First we need to import the library and then initialise it using
init() function. This function may take 2 arguments.
init(driverName string, debug bool)
- drivername : [Name of available driver] sapi5 on Windows | nsss on MacOS
- debug: to enable or disable debug output
After initialisation, we will make the program speak the text using
say() function. This method may also take 2 arguments.
say(text unicode, name string)
- text : Any text you wish to hear.
- name : To set a name for this speech. (optional)
Finally, to run the speech we use
runAndWait() All the
say() texts won’t be said unless the interpreter encounters
Code #1: Speaking Text
Code #2: Listening for events
It works offline, unlike other text-to-speech libraries. Rather than saving the text as audio file, pyttsx actually speaks it there. This makes it more reliable to use for voice-based projects.
- Python: Convert Speech to text and text to Speech
- Speech Recognition in Python using Google Speech API
- Convert Text to Speech in Python
- Convert Text to Speech in Python using win32com.client
- Text-To-Speech changing voice in Python
- Python | Convert image to text and then to speech
- Python | Text to Speech by using pyttsx3
- Text to speech GUI convertor using Tkinter in Python
- Speech To Text using IBM Watson Studio
- twitter-text-python (ttp) module - Python
- Part of Speech Tagging with Stop words using NLTK in python
- Python | Part of Speech Tagging using TextBlob
- Python | Speech recognition on large audio files
- Python - Get Today's Current Day using Speech Recognition
- NLP | Part of Speech - Default Tagging
- NLP | Part of speech tagged - word corpus
- Restart your Computer with Speech Recognition
- Convert Text and Text File to PDF using Python
- MySQL-Connector-Python module in Python
- Import module in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.