TEXT TO SPEECH PROGRAM
Kali ini saya akan membuat program text to speech dari google :
LISTING PROGRAM :
#sebelumnya menginstall library berikut:
#pip install tkinter
#pip install gTTS
#pip install playsound
#Mengimport Library
from tkinter import *
from gtts import gTTS
from playsound import playsound
import os
#menginisiasi window
root = Tk()
root.geometry ("350x300")
root.configure(bg='lavender')
root.title("TEXT TO SPEECH")
Label(root, text = "TEXT_TO_SPEECH", font = "arial 20 bold", bg='lavender', fg = 'ivory' ).pack()
Label(text ="Sekian", font = 'arial 15 bold', bg ='lavender' , fg = 'ivory' ,width = '20').pack(side = 'bottom')
Msg = StringVar()
Label(root,text ="Enter Text", font = 'arial 15 bold', bg ='lavender', fg = 'ivory').place(x=20,y=60)
entry_field = Entry(root, textvariable = Msg ,width ='50')
entry_field.place(x=20,y=100)
#fungsi mengubah text to Speech
def Text_to_speech():
Message = entry_field.get()
# inggris = en
# indonesia = id
# prancis = fr
# spanyol = es
# cina = zh-CN
# korea = ko
# Jepang = ja
speech = gTTS(text = Message, lang ='es')
speech.save('cekcek.mp3')
playsound('cekcek.mp3')
#fungsi keluar
def Exit():
root.destroy()
#fungsi reset
def Reset():
Msg.set("")
os.remove("cekcek.mp3")
#Button
Button(root, text = "PLAY", font = 'arial 15 bold' , command = Text_to_speech , bg = 'mediumpurple', fg = 'linen',width = '4').place(x=25,y=140)
Button(root, font = 'arial 15 bold',text = 'EXIT', width = '4' , command = Exit, bg = 'mediumorchid', fg = 'linen').place(x=100 , y = 140)
Button(root, font = 'arial 15 bold',text = 'RESET', width = '6' , command = Reset, bg = 'mediumpurple', fg = 'linen').place(x=175 , y = 140)
root.mainloop()
OUTPUT:
Komentar
Posting Komentar