Ad Code

Ticker

6/recent/ticker-posts

How to make a GUI text to speech app in Python | Very easy | Python | Abhicoder

      Hey guys! Wassup! I am glad to show you that what I made! So, I have basically made a TTS (Text To Speech) GUI software using Tkinter in Python 3.9. It too easy to code it. So, let's get into it, in detail.


So, You can see our final product at the top ☝ and for more detail, Video is below👇


Ooo my gad! Waoo!



So let's dive into detail

Process

So first open Sublime text 4 editor or any code editor you want. Then create a file and name it as 'main.py'. After that paste the code that, I have given in this post below. Then 'ctrl + s' means save and then you can RUN it! 

So, This was a simple step. But if you want to know about it in detail. Then see after the code.


Explanation:-

 

So, frist we need to import Tkinter. and then import ttk from tkinter. then we need to import ScrollableText for Tkinter.scrolledtext. Then from Tkinter.messagebox we need to import showinfo. And at the last Pyttsx3😤😵. And ower module importing process is completed! Now let's come to the code. Here frist we will define a function named 'Speak'. So then we have created a variable named 'engine' and it carrys the pyttsx3.int() means the whole pyttsx3. Then another variable named 'audio_string'. In this variable it is there that 'text.get('0,0' , END)' means that from the text area whatever text whould be there, will be stored in this variable. Then in the 'if' statement there is 'engine.say(audio_string)' means that we have made a variable

named engine, which was carrying the value of the 'pyttsx3', and here we tld the 'audio_string' means the 'pyttsx3' to say whatever is there in the Textarea. After that, We have to create a 'save_aud' function means to save the TTS (Text To Speech) into 'mp3' format. So just copy the whole 'Speak' function and paste it below. You need to make just a few changes. Frist Change the function name from 'Speak' to 'save_aud', after that there will be a function named 'engine.say(audio_string)' ,  change it to 'engine.save_to_file(audio_string, 'Abhicoder_Ai_Voice.mp3')'. And the last change At the last line of the function press enter and write 'showinfo('Abhicoder AI voice', 'File has been downloaded! Thanks for using!  :-) ') '. And that's it! After that, I have given a variable named 'root' which carries the value of the TK().  And the rest all are the GUI commands. In the gui command you can see that I have created 3 buttons. The code will be like 'ttk.Button(root,text='Read',width=9,command=speak).grid(row=1,column=0,ipadx=1,ipady=1)' In the first button, there is a 'command' section, Inside it you need to type 'speak'. This means that the function which we have defined is named 'speak'. Then in the second button, in the command section type 'text.delete('0.0',END)' means to delete the text from starting of the textarea to the end. In the third and last buttons, we need to type 'save_aud' means the function that we have created before to save the TTS (Text To Speech) into mp3 file. And that's it! We are done.

So, that's it guys for today's post, see you in the new post Till then Wear a mask and stay safe. If you like this video please like this video. And if you are new to my channel then please hit the red SUBSCRIBE and change it into SUBSCRIBED!

 Code is below!⏬⏬

Please support me to get

1000 subscribers as I always bring some new and interesting content for you! Thank you!

 

Keep Visiting! Goodbye!!

Want to try it online?:- https://abhicoderweb.blogspot.com/p/python-ide-online.html



Code is below!⏬




PYTHON code:-

from tkinter import*
from tkinter import ttk
from tkinter.scrolledtext import ScrolledText
from tkinter.messagebox import showinfo
import pyttsx3

def speak():
    engine = pyttsx3.init()
    audio_string = text.get('0.0',END)
    if audio_string:
        engine.say(audio_string)
        engine.runAndWait()
        engine.stop()

def save_aud():
    engine = pyttsx3.init()
    audio_string = text.get('0.0',END)
    if audio_string:
        engine.save_to_file(audio_string'Abhicoder_Ai_Voice.mp3')
        engine.runAndWait()
        engine.stop()
        showinfo('Abhicoder AI voice''File has been downloaded! Thanks for using!  :-) ')

root = Tk()
root.title('Abhicoder AI voice')
root.resizable(0,0)
#root.iconbitmap('robot3.ico')
root.configure(bg='red')

text = ScrolledText(root,width=35,height=15,bg='#ccc',fg='Red',wrapWORD,padx=10,pady=10,bd=2,relief=RIDGE)
text.grid(row=0,columnspan=3)

ttk.Button(root,text='Read',width=9,command=speak).grid(row=1,column=0,ipadx=1,ipady=1)
ttk.Button(root,text='Clear',width=9,command=lambdatext.delete('0.0',END)).grid(row=1,column=1,ipadx=1,ipady=1)
ttk.Button(root,text='Download',width=9,command=save_aud).grid(row=1,column=2,ipadx=1,ipady=1)

root.mainloop() {codeBox}

Post a Comment

0 Comments

Ad Code