Convert Text to Speech in Python using win32com.client
Last Updated : 29 Sep, 2022
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report
There are several APIs available to convert text to speech in python. One of such APIs available in the python library commonly known as win32com library. It provides a bunch of methods to get excited about and one of them is the Dispatch method of the library. Dispatch method when passed with the argument of SAPI.SpVoice It interacts with the Microsoft Speech SDK to speak what you type in from the keyboard.
Examples:
Input : Hello World
Output :
Input : 121
Output :
Installation
To install the win32com.client module , open terminal and write
pip install pypiwin32
This works on Windows platform. Now we are all set to write a sample program that converts text to speech.
Python
# Python program to convert# text to speech# import the required module from text to speech conversionimportwin32com.client# Calling the Dispatch method of the module which # interact with Microsoft Speech SDK to speak# the given input from the keyboardspeaker=win32com.client.Dispatch("SAPI.SpVoice")while1:print("Enter the word you want to speak it out by computer")s=input()speaker.Speak(s)# To stop the program press# CTRL + Z
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.