|
| 1 | +## import libraries |
| 2 | + |
| 3 | +from tkinter import * |
| 4 | +from gtts import gTTS |
| 5 | +from playsound import playsound |
| 6 | + |
| 7 | + |
| 8 | + |
| 9 | +################### Initialized window#################### |
| 10 | + |
| 11 | +root = Tk() |
| 12 | +root.geometry('350x300') |
| 13 | +root.resizable(0,0) |
| 14 | +root.config(bg = 'ghost white') |
| 15 | +root.title('Vishalsiingh - TEXT_TO_SPEECH') |
| 16 | + |
| 17 | + |
| 18 | +##heading |
| 19 | +Label(root, text = 'TEXT-TO-SPEECH' , font='arial 20 bold' , bg ='white smoke').pack() |
| 20 | +Label(root, text ='Vishalsiingh' , font ='arial 15 bold', bg = 'white smoke').pack(side = BOTTOM) |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | + |
| 25 | +#label |
| 26 | +Label(root, text ='Enter Text', font ='arial 15 bold', bg ='white smoke').place(x=20,y=60) |
| 27 | + |
| 28 | + |
| 29 | +##text variable |
| 30 | +Msg = StringVar() |
| 31 | + |
| 32 | + |
| 33 | +#Entry |
| 34 | +entry_field = Entry(root,textvariable =Msg, width ='50') |
| 35 | +entry_field.place(x=20 , y=100) |
| 36 | + |
| 37 | + |
| 38 | +###################define function############################## |
| 39 | + |
| 40 | +def Text_to_speech(): |
| 41 | + Message = entry_field.get() |
| 42 | + speech = gTTS(text = Message) |
| 43 | + speech.save('vishal.mp3') |
| 44 | + playsound('vishal.mp3') |
| 45 | + |
| 46 | +def Exit(): |
| 47 | + root.destroy() |
| 48 | + |
| 49 | +def Reset(): |
| 50 | + Msg.set("") |
| 51 | + |
| 52 | +#Button |
| 53 | +Button(root, text = "PLAY" , font = 'arial 15 bold', command = Text_to_speech, width =4).place(x=25, y=140) |
| 54 | +Button(root,text = 'EXIT',font = 'arial 15 bold' , command = Exit, bg = 'OrangeRed1').place(x=100,y=140) |
| 55 | +Button(root, text = 'RESET', font='arial 15 bold', command = Reset).place(x=175 , y =140) |
| 56 | + |
| 57 | + |
| 58 | +#infinite loop to run program |
| 59 | +root.mainloop() |
0 commit comments