Simple Text To Speech In Python

Simple Text To Speech In Python

Python offers a very good library to convert any text to speech. The library is known by the name “pyttsx3” and this is super easy to learn and use.

Features:

  • Works with Python versions 2 and 3 both
  • Works offline i.e. without an internet connection
  • It’s very fast and works without delay
  • Supports multiple TTS engines, including Sapi5, nsss, and espeak

Installation:

Inside your command prompt or your ide’s terminal type:

pip install pyttsx3

You may face this error

no module named 'pythoncom'

To resolve this you need to type

pip install pywin32

in your command prompt or ide’s terminal

If your error is one or more of the errors given below then your problem will be solved after installing pywin32

Errors may be:

  •  “No module named win32com.client”
  •  “No module named win32” or
  •  “No module named win32api”

Source Code

Now let’s have a look at the source code with an explanation

# import the pyttsx module inside program
import pyttsx3

# initializing the module
engine = pyttsx3.init()

# .say() function is used to speak the text you have written 
# inside the function
engine.say("Anything you write here will be spoken by your computer during the running of the program")

# this is used to process and run the program commands
engine.runAndWait()

Believe me! this program works perfectly so I suggest you try it at least once.


Also read:

Share:

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at admin@copyassignment.com Thank you