Machine Learning
Python project
Text to Speech in Python
Text to Speech in Python
Learn how to convert your Text into Voice with Python and Google APIs
Text to speech is a process to convert any text into voice. Text to speech project takes words on digital devices and convert them into audio with a button click or finger touch. Text to speech python project is very helpful for people who are struggling with reading.
Project Prerequisites
To implement this project, we will use the basic concepts of Python, Tkinter, gTTS, and playsound libraries.
1) Tkinter is a standard GUI Python library that is one of the fastest and easiest ways to build GUI applications using Tkinter.
2) gTTS (Google Text-to-Speech) is a Python library, which is a very easy library that converts the text into audio.
To install the required libraries, you can use pip install command:
1) pip install tkinter
2) pip install gTTS
3) pip install playsound
Text to Speech Python Project
The objective of this project is to convert the text into voice with the click of a button. This project will be developed using Tkinter, gTTs, and playsound library.
In this project, we add a message which we want to convert into voice and click on play button to play the voice of that text message.
Code:
from tkinter import*
from gtts import gTTS
from playsound import playsound
root = Tk()
root.title("DataFlair - TEXT_TO_SPEECH")
root.geometry('350x300')
root.configure(bg='ghost white')
Label(root, text = "TEXT_TO_SPEECH", font = "arial 20 bold", bg='white smoke').pack()
Label(text ="DataFlair", font = 'arial 15 bold', bg ='white smoke' , width = '20').pack(side = 'bottom')
Msg = StringVar()
Label(root,text ="Enter Text", font = 'arial 15 bold', bg ='white smoke').place(x=20,y=60)
entry_field = Entry(root, textvariable = Msg ,width ='50')
entry_field.place(x=20,y=100)
def Text_to_speech():
Message = entry_field.get()
speech = gTTS(text = Message)
speech.save('DataFlair.mp3')
playsound('DataFlair.mp3')
def Exit():
root.destroy()
def Reset():
Msg.set("")
Button(root, text = "PLAY", font = 'arial 15 bold' , command = Text_to_speech ,width = '4').place(x=25,y=140)
Button(root, font = 'arial 15 bold',text = 'EXIT', width = '4' , command = Exit, bg = 'OrangeRed1').place(x=100 , y = 140)
Button(root, font = 'arial 15 bold',text = 'RESET', width = '6' , command = Reset).place(x=175 , y = 140)
root.mainloop()
Output:
No comments