How to create a basic text to speech bot using python

Image Source - https://qatechtalks.medium.com/


When we say text-to-speech (TTS), We are talking about assertive technology which reads any text and speaks aloud. In today's digital world, we have multiple applications, where this text-to-speech technology can be used. 

A few of the applications are listed below - 

  • Audio book narration
  • Voice assistant for old age and people with disabilities
  • Helping people with speech disorders
  • Helping students pursuing foreign languages

Today we are going to write a basic Python text-to-speech program. Which is going to read the message loud which we are passing to it.

To Create a basic text-to-speech converter we are going to use `pyttsx3` library. Which provides a very simple interface for text-to-speech conversion. 

Step-by-step guide to create a basic text-to-speech converter - 

1 - Download the pyttsx module using pip or pip3(If you are using Python3)


pip install pyttsx3


2 - Create a python script to import the pyttsx3 library - 


import pyttsx3


3 - Initialize text-to-speech engine - 

engine = pyttsx3.init()


4 - Define a function which will read the provided text aloud

def text_to_speech(text):
engine.say(text)
engine.runAndWait()


5 - Call the above method by passing some text - 


text_to_read = "Hello, welcome to the geek mode text reader!"
text_to_speech(text_to_read)


Your text-to-speech bot is ready. You can modify and send any string message and this program will read that aloud. 

Complete Program - 

import pyttsx3

engine = pyttsx3.init()

def text_to_speech(text):
engine.say(text)
engine.runAndWait()

text_to_read = "Hello, welcome to the geek mode text reader!"
text_to_speech(text_to_read)


You can explore more around above library here, and can add more feature in te above program. You can also try to automate the process to read anything you want.

Comments