Firstly, to convert text to speech in python we need to install a python library known as pyttsx3 using the following command :
pip install pyttsx3
After that execute the code below and listen your desired sentence..
Source Code :
import pyttsx3
Initialize the engine
engine = pyttsx3.init()
Set the rate
engine.setProperty('rate', 150)
Set the volume
engine.setProperty('volume', 0.9)
Say the sentence
engine.say('Hello my name is raj !!!')
Wait for the engine to finish
engine.runAndWait()
Deatiled Explaination :
This Python code utilizes the `pyttsx3` library to convert text into speech. Below is a detailed explanation of each part of the code:
1. `import pyttsx3`: This line imports the `pyttsx3` library, which is a text-to-speech conversion library in Python.
2. `engine = pyttsx3.init()`: This line initializes the text-to-speech engine. It creates an instance of the `Engine` class, which is the core component of `pyttsx3`.
3. `engine.setProperty('rate', 150)`: This line sets the speaking rate of the engine to 150 words per minute. You can adjust this value to control how fast or slow the text is spoken.
4. `engine.setProperty('volume', 0.9)`: This line sets the volume of the speech output to 90%. You can adjust this value between 0 and 1 to control the volume.
5. `engine.say('Hello, world!')`: This line instructs the engine to convert the text "Hello, world!" into speech. You can replace this text with any string you want to be spoken aloud.
6. `engine.runAndWait()`: This line instructs the engine to speak the text and wait until it finishes speaking before executing further code. Without this line, the program might terminate before the text is spoken completely.
In summary, this code initializes a text-to-speech engine, sets parameters such as speaking rate and volume, converts the text "Hello, world!" into speech, and then speaks it out loud at the specified rate and volume.
Important Links :
https://pypi.org/project/pyttsx3/
----------------------------------------------------------------------------------------------------------------------------------------------------
Social Media : #Connectwithme
►Facebook : / raj.podder.524
►Twitter : / rajpoddar8907
►Instagram : / raj_rp18