Python 3 pyttsx3 Text to Speech Bot Tkinter GUI Desktop App with Different Voices and Speed Full Project For Beginners

Python 3 pyttsx3 Text to Speech Bot Tkinter GUI Desktop App with Different Voices and Speed Full Project For Beginners


Welcome folks today in this blog post we will be making text to speech bot desktop app in tkinter using pyttsx3 library in python. All the source code of the application wil be given below.




Get Started




In order to get started you need to install the following libraries using the pip command as shown below


pip install tkinter


pip install pyttsx3


After installing these libraries inside your python project just make an file and copy paste the following code to it



from tkinter import *
import pyttsx3 

class Bot:
    def __init__(self, root, engine):
        self.engine = engine
        self.engine.say('Hi! I am your friend!. Please give me a name')
        botName = input()
        self.engine.say('Thanks for such a wonderful name.')
        self.engine.say(str(botName + 'will, help you...'))
        #self.engine.say('I will try to repeat whatever you say. ')
        self.engine.say('Please proceed')
        self.root = root
        self.voiceValue = IntVar()

    def DialogBox(self):
        dialog = Toplevel()

    def DialogMan(self, message):
        if message:
    def clear(self, e1):
        e1.delete(0, 'end')

    #def voiceSpeed(self, voiceVal):
        #value = Label(self.root, text=voiceVal)
        #value.grid(row=5, column=23)
        #self.engine.setProperty('rate', voiceVal)

    def voiceSpeed(self):
        print('In voiceSpeed funcs with speed = ', self.voiceValue.get())
        if not self.voiceValue.get():
            self.VoiceValue.set(30)     # = 30
        value = Label(self.root, text=str(self.voiceValue.get()))
        value.grid(row=5, column=23)
        self.engine.setProperty('rate', self.voiceValue.get())

    def showMe(self, msg):
        message = Message(root, text=msg)
        message.grid(row=5, column=10)

    def byeBye(self):
        self.engine.say('Ok, Bye. Nice to talk to you!')
    def process(self):
        l1 = Label(self.root, text='Your message')

        e1 = Entry(root)
        e1.grid(row=0, column=5)
        e1.bind('<Return>', (lambda event: self.DialogMan(e1.get())))
        e1.bind('<Escape>', (lambda event: self.clear(e1)))

        showButton = Button(self.root, bg='green', text='Repeat It', width=20, command=lambda: self.DialogMan(e1.get()))
        showButton.grid(row=5, column=0)
        clearButton = Button(self.root, bg='yellow', text='Clear It', width=20, command=lambda: self.clear(e1))
        clearButton.grid(row=10, column=0)      

        quitButton = Button(self.root, bg='red', text='Bye', width=20, command=lambda: self.byeBye())
        quitButton.grid(row=15, column=0)
        # Can use scale, but change wasn't effective
        #voiceRate = Scale(self.root, from_=20, to=150, orient=HORIZONTAL, command=lambda val: self.voiceSpeed(voiceRate.get()))
        #voiceRate.grid(row=20, column=10)
        rate1 = Radiobutton(self.root, text='10', variable = self.voiceValue, value=10, command=self.voiceSpeed)
        rate1.grid(row=20, column=0)
        rate1 = Radiobutton(self.root, text='1', variable = self.voiceValue, value=1, command=self.voiceSpeed)
        rate1.grid(row=22, column=0)
        rate1 = Radiobutton(self.root, text='2', variable = self.voiceValue, value=2, command=self.voiceSpeed)
        rate1.grid(row=24, column=0)
        rate1 = Radiobutton(self.root, text='340', variable = self.voiceValue, value=340, command=self.voiceSpeed)
        rate1.grid(row=26, column=0)
        rate1 = Radiobutton(self.root, text='450', variable = self.voiceValue, value=450, command=self.voiceSpeed)
        rate1.grid(row=28, column=0)
        rate1 = Radiobutton(self.root, text='560', variable = self.voiceValue, value=560, command=self.voiceSpeed)
        rate1.grid(row=30, column=0)
        rate1 = Radiobutton(self.root, text='6', variable = self.voiceValue, value=6, command=self.voiceSpeed)
        rate1.grid(row=32, column=0)
        rate1 = Radiobutton(self.root, text='50', variable = self.voiceValue, value=50, command=self.voiceSpeed)
        rate1.grid(row=34, column=0)
        rate1 = Radiobutton(self.root, text='120', variable = self.voiceValue, value=120, command=self.voiceSpeed)
        rate1.grid(row=36, column=0)
        rate1 = Radiobutton(self.root, text='150', variable = self.voiceValue, value=150, command=self.voiceSpeed)
        rate1.grid(row=38, column=0)
        rate1 = Radiobutton(self.root, text='180', variable = self.voiceValue, value=180, command=self.voiceSpeed)
        rate1.grid(row=40, column=0)

root = Tk()

engine = pyttsx3.init()

newBot = Bot(root, engine)


print("Things are normal now. !!")


See also  Python 3 Selenium Script to Send Direct Message to any Username Using Instagram API Full Project For Beginners


Now if you execute the python script you will see the text to speech bot wil be launched and you can write the text what you want the bot to speak in different voices and speed as shown below

See also  Python Script to Convert CSV File to HTML Table Using Pandas Library Full Tutorial For Beginners




Leave a Reply