How to make text to speech converter in python

text to speech converter in python
Table of Contents

Hello programmers welcome to coderzway today I am going to show how to make text to speech converter in python yeah we will create our own text to speech program you don’t download any applications to convert your text to voice.

There are many ways of doing this in python but I am going to show you the most easy and simple way we will use the pyttsx3 python library for audio converting in our text to speech program.

It is very simple project the user will enter the text they want to convert then the voice will be converted into male robot and it will be saved in your computer you see you can easily convert text to speech in python.

You can also use female robot voice and change the speed of the robot you can customise and create a application from this it depends on your creativity.

If you want more coding projects than you should visit coderzway projects there we upload daily cool projects with source code you can go coderzway projects page here.

Making a text to speech converter in python

So first thing you need to have on your computer or laptop is python installed if you don’t have python installed go to python website and download and install remember to click add python to path while installing.

To download python go to the python official website here – download python.

Create a python file

Now go to any folder and open it in vs code or any code editor and create a python file with .py extension.

To download vs code go to this website – download vs code.

Install pyttsx3

Now you have created the python file now open a terminal or command prompt at the file location and install pyttsx3 to install it paste or type the below command

				
					pip install pyttsx3

				
			

pyttsx3 is a python library which is going to help us to convert text to speech in python this is a great and small library

Copy and paste python code

				
					# import pyttsx3 download it like this pip install pyttsx3
import pyttsx3

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
engine.setProperty('voice',voices[0].id) # for male voice use this
# engine.setProperty('voice',voices[1].id) # for female voice use this

engine.setProperty('rate', 100) # the speed of the speed it is words per min

print('Welcome to text to speech generator')
text = input('Enter your text \n')

filename = input('Name this audio file : ')
engine.save_to_file(text, f'{filename}.mp3') # for saving the file
engine.runAndWait()

print(f'Your file has been saved in this program folder with the name {filename}.mp3')



				
			

After copying and pasting the code run the file

To run the file type or paste the following command in the terminal or command prompt at the file location

				
					# enter the name of your file
python filename.py 
				
			


This will run the file you should see this as output

Output

				
					Welcome to text to speech generator
Enter your text
Hello this is the text I want to convert to audio
Name this audio file : audio
Your file has been saved in this program folder with the name audio.mp3
				
			

First it will ask you to enter the text you want to convert to speech than it will ask you to enter the name of audio file you want to save as don’t name existing file name this will overide it.

Summary

So this was the project on how to make text to speech converter in python it was a simple and easy project you can expand upon it by making voice assistant and more.

I hope you found this article helpful and if loved this and want more projects like this than do subscribe to our newsletter and share it with your friends and family thank you have a nice day.

Share This Post
Share on facebook
Share on twitter
Share on email
Share on whatsapp

Leave a Reply

Subscribe To Our Newsletter

Get updates and learn from the best

Latest Guides & Articles