Convert Text to Speech in Python using win32com.client

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.

filter_none

edit
close

play_arrow

link
brightness_4
code

# Python program to convert
# text to speech
  
# import the required module from text to speech conversion
import win32com.client
  
# Calling the Disptach method of the module which 
# interact with Microsoft Speech SDK to speak
# the given input from the keyboard
  
speaker = win32com.client.Dispatch("SAPI.SpVoice")
  
while 1:
    print("Enter the word you want to speak it out by computer")
    s = input()
    speaker.Speak(s)
  
# To stop the program press
# CTRL + Z

chevron_right


Input:

 Welcome to geeks for geeks

Output:


This article is contributed by Subhajit Saha. If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.



My Personal Notes arrow_drop_up


Article Tags :

2


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.