Amazing-Python-Scripts

Форк
0
59 строк · 1.2 Кб
1
# import libraries
2
import os
3
from tkinter import *
4
from gtts import gTTS
5
from playsound import playsound
6

7
# Initialized window
8

9
root = Tk()
10
root.geometry('600x300')
11
root.resizable(0, 0)
12
root.config(bg='ghost white')
13
root.title('TEXT TO SPEECH')
14

15

16
# heading
17
Label(root, text='Convert your Text into Voice',
18
      font='arial 20 bold', bg='white smoke').pack()
19

20
# label
21
Label(root, text='Enter Text', font='arial 15 bold',
22
      bg='white smoke').place(x=20, y=60)
23

24
# text variable
25
Msg = StringVar()
26

27
# Entry
28
entry_field = Entry(root, textvariable=Msg, width='60')
29
entry_field.place(x=20, y=100)
30

31
# define function
32

33

34
def Text_to_speech():
35
    Message = entry_field.get()
36
    speech = gTTS(text=Message)
37
    speech.save('Data.mp3')
38
    playsound('Data.mp3')
39
    os.remove('Data.mp3')
40

41

42
def Exit():
43
    root.destroy()
44

45

46
def Reset():
47
    Msg.set("")
48

49

50
# Button
51
Button(root, text="PLAY", font='arial 15 bold',
52
       command=Text_to_speech, width=4).place(x=25, y=140)
53
Button(root, text='EXIT', font='arial 15 bold',
54
       command=Exit, bg='OrangeRed1').place(x=100, y=140)
55
Button(root, text='RESET', font='arial 15 bold',
56
       command=Reset).place(x=175, y=140)
57

58
# infinite loop to run program
59
root.mainloop()
60

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.