Welcome Folks today in this blog post I will be talking about how to convert text to audio using gtts library in a gui application using tkinter library in python. Let’s get started step by step in the youtube video as follows.
Requirements
1 |
pip install tkinter |
1 |
pip install gtts |
Now after installing these two libraries copy paste the following code to make this application. In this block of code we will be making the gui application using tkinter and then writing the code to convert the text written to a audio file and play the audio file also. For Playing the audio file we will be installing another library called PlaySound.
1 |
pip install playsound |
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 |
from tkinter import * from gtts import gTTS from playsound import playsound def convert_audio(): address_info = address.get() language = 'en' myobj = gTTS(text=address_info, lang=language, slow=False) myobj.save("welcome.mp3") playsound("welcome.mp3") print(address_info) address_entry.delete(0,END) app = Tk() app.geometry("500x500") app.title("Python Text to Audio App") heading = Label(text="Python Text to Audio",bg="yellow",fg="black",font="10",width="500",height="3") heading.pack() address_field = Label(text="Text :") address_field.place(x=15,y=70) address = StringVar() address_entry = Entry(textvariable=address,width="30") address_entry.place(x=15,y=100) button = Button(app,text="Convert to Audio",command=convert_audio,width="30",height="2",bg="grey") button.place(x=15,y=140) mainloop() |