Python 3 Tkinter GUI Script to Convert Text to Speech Mp3 Audio Using pyttsx3 Library Full Tutorial For Beginners

Python 3 Tkinter GUI Script to Convert Text to Speech Mp3 Audio Using pyttsx3 Library Full Tutorial For Beginners

 

Welcome folks today in this blog post we will be making text to speech app in tkinter library. For this purpose we will be also be using pyttsx3 library for converting the text to mp3 speech in various voices. All the full source code of the application is given below.

 

 

 

 

Get Started

 

 

 

In order to get started we need to install the following library by using the pip command as shown below

 

pip install tkinter

 

pip install pyttsx3

 

After installing all these libraries make an app.py file and copy paste the following code

 

app.py

 

 

from tkinter import *
import pyttsx3
engine=pyttsx3.init()


def sRate():
   voices=engine.getProperty('voices')
   engine.setProperty('voice',voices[1].id)
    
def male():
   voices=engine.getProperty('voices')
   engine.setProperty('voice',voices[0].id)
   
def female():
   voices=engine.getProperty('voices')
   engine.setProperty('voice',voices[2].id)   
   
   
def speak():
    text_entered=textentry.get()
    engine.say(text_entered)
    engine.runAndWait()
def exit_program():
    window.destroy()
    exit()

    
    
window=Tk()


window.configure(background="black")
window.title("Text to Speech Program")
Label(window,text="Enter text",bg="black", fg="white",font="Arial 16 bold").grid(row=0,column=0,sticky=W)
textentry=Entry(window,width=20,bg="white")
textentry.grid(row=1,column=0,sticky=W)
Button(window,text="Submit",width=6,command=speak).grid(row=2,column=0,sticky=W)
Label(window,text="Click to close",bg="black",fg="white",font="Arial 12 underline").grid(row=3,column=0,sticky=W)
Label(window,text="Gender",bg="black",fg="white",font="Arial 12 underline").grid(row=0,column=3,sticky=E)
Button(window,text="Male",width=6,command=male).grid(row=3,column=2,sticky=E)
Button(window,text="Female",width=6,command=sRate).grid(row=3,column=3,sticky=E)
Button(window,text="Female 2",width=6,command=female).grid(row=3,column=4,sticky=E)



Button(window,text="Close",width=6,command=exit_program).grid(row=4,column=0,sticky=W)


window.mainloop()

 

READ  Python 3 Tkinter Script to Build Advanced Base Unit Converter (Weight + Distance + Length + Volume Temperature + Area + Height) GUI Desktop App Full Project For Beginners

 

 

Now if you execute this python app by executing the below command

 

python app.py

 

 

 

 

So you will enter the text inside the tkinter gui and then you can select the gender voice either male or female and then you can click the submit button then it will speak those words in the respective voice that is selected.

Leave a Reply