πŸ”Š AI-Powered Text-to-Speech Converter in Python – Convert Text to Voice!

  Demo :


Click Video πŸ‘‡πŸ‘‡πŸ‘‡











Code : 

import os

import tkinter as tk

from tkinter import filedialog, messagebox

from gtts import gTTS


# Function to convert text to speech

def text_to_speech():

    text = text_entry.get("1.0", tk.END).strip()

    if not text:

        messagebox.showerror("Error", "Please enter text!")

        return


    try:

        tts = gTTS(text=text, lang='en')

        file_path = filedialog.asksaveasfilename(defaultextension=".mp3",

                                                 filetypes=[("MP3 files", "*.mp3")])

        if file_path:

            tts.save(file_path)

            messagebox.showinfo("Success", "Speech saved successfully!")

    except Exception as e:

        messagebox.showerror("Error", f"Something went wrong: {e}")


# GUI Setup

root = tk.Tk()

root.title("AI Text-to-Speech Converter")

root.geometry("400x300")

root.resizable(False, False)


# UI Elements

tk.Label(root, text="Enter Text:", font=("Arial", 12)).pack(pady=5)

text_entry = tk.Text(root, height=5, width=40)

text_entry.pack(pady=5)


convert_btn = tk.Button(root, text="Convert to Speech", font=("Arial", 12), command=text_to_speech)

convert_btn.pack(pady=10)


root.mainloop()


Comments

Popular posts from this blog

πŸš€ Simple Login & Registration System in Python Tkinter πŸ“±

πŸš€ Create a Python Screen Recorder with Audio (Complete Code)

Python IP Tracker App with GUI | Track IP Location Real-Time! (Working Project)