PyTTSx3
PyTTSx3:
Pyttsx3 is a Python library that provides a simple and efficient way to interact with text-to-speech (TTS) engines. It allows you to convert written text into spoken words, giving your Python programs the ability to communicate with users through speech.
To use pyttsx3, you’ll first need to install it.
You can do this by running the following command in your terminal:
pip install pyttsx3
Once installed, you can import the library into your Python script and start using it:
import pyttsx3
# Initialize the TTS engine
engine = pyttsx3.init()
# Set the properties of the voice
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) # You can change the voice index to switch to a different voice
# Convert text to speech
text = "Hello, how are you?"
engine.say(text)
# Play the speech
engine.runAndWait()
In the example above, we initialize the pyttsx3 engine and set the voice property to the first available voice. You can explore the voices
list to see the available voices and choose the one you prefer.
Then, we use the say
method to convert the text to speech. Finally, we use the runAndWait
method to play the speech and wait until it finishes.
Pyttsx3 also provides additional features, such as controlling the speed and volume of the speech, as well as adding callbacks for events like the start and end of speech. You can refer to the pyttsx3 documentation for more details on these features and additional examples.
Python Training Demo Day 1
Conclusion:
Unogeeks is the No.1 IT Training Institute for Python Training. Anyone Disagree? Please drop in a comment
You can check out our other latest blogs on Python here – Python Blogs
You can check out our Best In Class Python Training Details here – Python Training
Follow & Connect with us:
———————————-
For Training inquiries:
Call/Whatsapp: +91 73960 33555
Mail us at: info@unogeeks.com
Our Website ➜ https://unogeeks.com
Follow us:
Instagram: https://www.instagram.com/unogeeks
Facebook: https://www.facebook.com/UnogeeksSoftwareTrainingInstitute
Twitter: https://twitter.com/unogeeks