Python : Making text to speech converter in Python with pyttsx3 module
Today in this article we are going to do some fun. We will translate the string into speech with the help of pyttsx3 module.
So let’s start
First we will download pyttsx3 with pip
pip install pyttsx3
Code : Python program to convert text to speech
# Importing pyttsx3 Import pyttsx3 # Gets a reference to an engine instance that will use the given driver engine = pyttsx3.init() # say method on the engine that passing input text to be spoken engine = say("Python is awesome") # run and wait method, it processes the voice commands engine.runAndWait()
It will say Python is awesome
Saving voice to a file
import pyttsx3 engine = pyttsx3.init() # Method to save file engine.save_to_file("Python is awesome", "D:\pyhon1.mp3") engine.runAndWait()
Changing speech rate
import pyttsx3 engine = pyttsx3.init() rate = engine.getProperty('rate') engine.setProperty('rate', rate+100) engine.save_to_file("Python is awesome","D:\python2.mp3") engine.runAndWait()
Use cases of text to speech conversion
- Used for blind people who can’t see but can listen.
- “Text to Speech” option is a very good idea when needing to make sure the information will be communicated correctly.
- It is used in metros and buses.
For more details on pyttsx3 – you will get all the details in this documentation – https://pyttsx3.readthedocs.io/en/latest/
Thank You for reading 📖
Have a nice day!!