Python Text To Speech | pyttsx module Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report 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 Usage – 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 runAndWait(). Code #1: Speaking Text # importing the pyttsx library import pyttsx3 # initialisation engine = pyttsx3.init() # testing engine.say("My first code on text-to-speech") engine.say("Thank you, Geeksforgeeks") engine.runAndWait() Code #2: Listening for events import pyttsx3 def onStart(): print('starting') def onWord(name, location, length): print('word', name, location, length) def onEnd(name, completed): print('finishing', name, completed) engine = pyttsx3.init() engine.connect('started-utterance', onStart) engine.connect('started-word', onWord) engine.connect('finished-utterance', onEnd) sen = 'Geeks for geeks is a computer portal for Geeks' engine.say(sen) engine.runAndWait() Why pyttsx? 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. Don't miss your chance to ride the wave of the data revolution! Every industry is scaling new heights by tapping into the power of data. Sharpen your skills and become a part of the hottest trend in the 21st century. Dive into the future of technology - explore the Complete Machine Learning and Data Science Program by GeeksforGeeks and stay ahead of the curve. Last Updated : 14 Jan, 2019 Like Article Save Article Previous Convert Text to Speech in Python Next Python: Convert Speech to text and text to Speech Share your thoughts in the comments Add Your Comment Please Login to comment... Similar Reads Python: Convert Speech to text and text to Speech Speech Recognition in Python using Google Speech API 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 Convert PDF File Text to Audio Speech using Python Extract speech text from video in Python Convert Text to Speech in Python Convert Text to Speech in Python using win32com.client Complete Tutorials Python Crash Course Python API Tutorial: Getting Started with APIs Advanced Python Tutorials Python Automation Tutorial OpenAI Python API - Complete Guide Like N NaazneenJatu Follow Article Tags : Python Practice Tags : python Additional Information Current difficulty : Easy Vote for difficulty : Easy Normal Medium Hard Expert