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