Converting text-to-speech  using python: pyttsx3 library

Photo by Andrew Neel on Unsplash

Converting text-to-speech using python: pyttsx3 library

Who is this for?

This article is for beginners who are just learning python and wish to understand how to convert a simple text-to-speech.

Introduction

Text-to-speech systems, also known as TTS, were first developed to aid the visually impaired by offering a computer-generated spoken voice that would “read” text to the user.

Text-to-speech model is a small application or bot which converts the given text into speech.

Text-to-speech has become a part of our everyday lives we find them in articles, books, and smartphones among all others.

Prerequisites

  • Knowledge of python 3 or higher

  • Computer and internet

  • Vscode installed or any other editor

Getting started

  1. create a folder called text-speech

  2. open in vs code

  3. create a file called text.py

Writing the code

  • Create your virtual environment:
#in your terminal do the following 
> py -m venv env 
# click enter
> env\Scripts\Activate

you have successfully created your virtual environment with the name env

  • Installing python package pyttsx3 using pip
(env) PS C:\Users\user\desktop\text-speech> pip install pyttsx3
  • Meaning of various functions used in this program:

pyttsx3: is a text-to-speech conversion library in Python. It is a very easy-to-use tool which converts a given text into speech.

pyttsx3.init(): the init function is the main function, we have to use this function every time. This function initializes the connection.

.say: to input any word you want to be converted.

runAndWait(): will make the speech audible in the system, if you don't write this command then the speech will not be audible to you.

  • The program
import pyttsx3
engine = pyttsx3.init()
engine.say('hello reader')
engine.runAndWait()

Conclusion

In this article, we walk through how to use the pyttsx3 library to convert text-to-speech. you can learn more about the library at https://pypi.org/project/pyttsx3/

Thanks for reading!!!!!