Text to Speech Converter Using Python

Introduction :

Hello friends! So in today’s post I am going to tell you how you can convert any text into speech with the help of Python Programming Language. If you also want to know about it, then read this article till the end and read it carefully so that you understand everything correctly.

Text to Speech Converter :

Friends, in this project of our Text to Speech Converter, first of all we will take input from the user in the form of text and after that our computer will speak that text.

Library Installation :

Friends, to do this project, you will need a Python library named pywin32, so first of all you have to install this library in your system (computer), you can use pip command to install it.

pip install pywin32

Code For Converting Text To Speech

def speak(str):
    from win32com.client import Dispatch
    speak=Dispatch("SAPI.SpVoice")
    speak.speak(str)

title=input("Enter Any Text:")
speak(title)

Explanation :

1. Friends, in this program we have created a Function named “speak” and inside it an Argument named “str” has been given.

2. And after that a function named Dispatch has been imported from the library of “win32com.client”, and with the help of this we will convert Text into Speech.

3. And after that we have created a variable named “speak” and we have stored the type of voice we want in the variable named “speak”.

4. After that we have written “speak.speak(str)” to speak the text written by the user.

5. After that, outside this function, we have created a variable named “title” and in this we will take input from the user.

6. And after that in the last “speak” function will be called and title will be written in place of “str”.

7. After that, whatever text the user writes, the “speak” function will show it by speaking.

Summary :

So friends, now I hope that you must have learned to convert any text into speech with the help of Python Programming Language. So if you like this article then please tell us by commenting and if you want to know about more similar Python projects then follow us and subscribe to our Youtube Channel “CodeWithShani“, Thank you!

Leave a Reply

Your email address will not be published. Required fields are marked *