How to make our computer spout off the text we printed?
In this blog we will see how to make our computer spout off what we printed in form of text with the help of Python. All we need to do is write a few lines of code and get it compiled.
When we are converting the text to a speech in our computer then it is said to be speech synthesizer. A text-to-speech(TTS) can convert the text to speech.
Now let us dive into the coding part.
We need to install a module to start with the code. pip install pyttsx3 Why pyttsx3? It is a module which will take care of the libraries required for text to speech conversion. Now import the installed module. import pyttsx3 Now call for the engine. engine = pyttsx3.init() Why pyttsx3.init() factory function? This helps us to get a allusion to a pyttsx3. Now we have to invoke what we want our compiler to speak. engine.say("Welcome to prequelcoding.in a guide to learn coding.") Now last but not the least we have to ask the engine to runAndWait Why? This makes the speech to be audible to the user if we are not going to invoke this statement then we might not hear to the sentences we have invoked. engine.runAndWait() Full Code: import pyttsx3 engine = pyttsx3.init() engine.say("Welcome to prequelcoding.in a guide to learn coding.") engine.runAndWait()
The compiler then spout off what you have invoked while inputting.