from tkinter import * 
from tkinter.ttk import *
from gtts import gTTS
from playsound import playsound

#converts text to speech
def make_speech():
    tts = gTTS(txt.get())
    tts.save(PATH)
    playsound(PATH)

#will be used for storing speech.mp3 
PATH = "C:\\Users\\Aparajita\\Documents\\speech.mp3"

#make the window object
root = Tk()
root.title("Text to Speech")
root.geometry("400x200")
root.config(bg='#4fe3a5')

#will store the speech as text
txt = StringVar()

#create a label
label = Label(root,
              text ="Enter text:",
              font= ('Helvetica 15 bold')).place(relx=0.5,rely=0.1,anchor=CENTER)
#create a textbox
speech_entry = Entry(root,
                   textvariable = txt,
                   font=('calibre',10,'normal')).place(relx=0.5,rely=0.3,anchor=CENTER)
#create a button
speak_btn = Button(root,text = 'Speak',
                  command = make_speech).place(relx=0.5,rely=0.5,anchor=CENTER)

#keep the window running
root.mainloop()
