Amazing-Python-Scripts
59 строк · 1.2 Кб
1# import libraries
2import os3from tkinter import *4from gtts import gTTS5from playsound import playsound6
7# Initialized window
8
9root = Tk()10root.geometry('600x300')11root.resizable(0, 0)12root.config(bg='ghost white')13root.title('TEXT TO SPEECH')14
15
16# heading
17Label(root, text='Convert your Text into Voice',18font='arial 20 bold', bg='white smoke').pack()19
20# label
21Label(root, text='Enter Text', font='arial 15 bold',22bg='white smoke').place(x=20, y=60)23
24# text variable
25Msg = StringVar()26
27# Entry
28entry_field = Entry(root, textvariable=Msg, width='60')29entry_field.place(x=20, y=100)30
31# define function
32
33
34def Text_to_speech():35Message = entry_field.get()36speech = gTTS(text=Message)37speech.save('Data.mp3')38playsound('Data.mp3')39os.remove('Data.mp3')40
41
42def Exit():43root.destroy()44
45
46def Reset():47Msg.set("")48
49
50# Button
51Button(root, text="PLAY", font='arial 15 bold',52command=Text_to_speech, width=4).place(x=25, y=140)53Button(root, text='EXIT', font='arial 15 bold',54command=Exit, bg='OrangeRed1').place(x=100, y=140)55Button(root, text='RESET', font='arial 15 bold',56command=Reset).place(x=175, y=140)57
58# infinite loop to run program
59root.mainloop()60