Text to Speech GUI Converter using Python | Pyttsx3 use in Python.



Text to Speech using Python



Tkinter is the standard GUI library for Python. Python when combined with tkinter provides a fast and easy way to create GUI applications.By this library we can make a compelling choice for building GUI applications in Python, especially for applications where a modern sheen is unnecessary, and the top priority is to build something that’s functional and cross-platform quickly.

To create a tkinter application:

  1. Importing the module – tkinter
  2. Create the main window (container)
  3. Add any number of widgets to the main window
  4. Apply the event Trigger on the widgets.

Now, Let’s create a GUI-based Text to speech converter application which converts text into speech.

There are lots of libraries in python one of them is pyttsx3(Python text-to-speech version-3), a Python library to Translate’s text-to-speech.


To install pyttsx3 simply go to your terminal and type:

pip install pyttsx3


Below is the implementation of the code :


import pyttsx3
from tkinter import *
import tkinter
from tkinter import messagebox

root=tkinter.Tk()
root.title("Text into Speech-By Shubham Sagar")

root.geometry("400x500")

root.iconbitmap("C:/Users/hp/Downloads/hnet.com-image.ico")

def speak():
    try:
        engine = pyttsx3.init()
        new_var=e1.get()

        engine.say(new_var)

        engine.runAndWait()
    except:
        messagebox.showerror("Wrong input","Enter Correct Input")

def check():

    var_new=e1.get()
    if len(var_new)==0:
        messagebox.showerror("Enter Again","Dont Leave the input space!!")
    else:
        pass

l1=Label(root, text="SPEECH INTO TEXT",font=("Algerian",20),fg="red",bg="black")#Create a Label

l1.pack()

l2=Label(root, text="Enter Text Below",font=("MS Sans Serif",15), fg="cyan"bg="yellow")
l2.pack(padx=30,pady=40)

ans=StringVar()
e1=Entry(root,font=("Verdana",10),textvar=ans,width=20)

e1.pack()

btn=Button(root,text="Speak Now!",fg="blue",bg="black",command=speak)

btn.pack(padx=50,pady=50ipadx=15,ipady=10)

check()
root.resizable(width=0,height=0)

if __name__=="__main__":
    root.mainloop()



Ready to Solve your Problems in the comment Section !




4 comments:

  1. Thank you sir your we are happy to know that you enjoyed this post. Keep sharing keep loving, keep supporting.

    ReplyDelete
  2. Thanks for sharing the post.. parents are worlds best person in each lives of individual..they need or must succeed to sustain needs of the family. https://btclod.com

    ReplyDelete

Powered by Blogger.