AI / ChatGPT
AI Consultancy

The Current State of Translation Services: A Visual Overview

Posted on October 29, 2023 in AI,ChatGPT,ChatGPT-3.5,languages,Projects,software,Sound by Stefaan Meeuws

A picture says more than a thousand words, so here is the current state of the translation service part of the project.

And the Python script so far:

import tkinter as tk
from tkinter import filedialog
from googletrans import Translator
from gtts import gTTS
import playsound

def translate_text(text, source_lang, target_lang):
    translator = Translator()
    translated = translator.translate(text, src=source_lang, dest=target_lang)
    return translated.text

def open_file():
    file_path = filedialog.askopenfilename(filetypes=[("Text Files", "*.txt")])
    if file_path:
        with open(file_path, "r", encoding="utf-8") as file:
            source_text.delete(1.0, tk.END)  # Clear existing text

def translate_and_speak():
    source_language = source_language_var.get()
    target_language = target_language_var.get()
    source_text_str = source_text.get(1.0, tk.END)
    translated_text_str = translate_text(source_text_str, source_language, target_language)
    translated_text.delete(1.0, tk.END)
    translated_text.insert(tk.END, translated_text_str)
    speech = gTTS(text=translated_text_str, lang=target_language, slow=False, tld="")"TTSpeech.mp3")

# Create the main window
root = tk.Tk()
root.title("Text Translator")

# Create menu system
menu = tk.Menu(root)

file_menu = tk.Menu(menu)
menu.add_cascade(label="File", menu=file_menu)
file_menu.add_command(label="Open", command=open_file)

language_menu = tk.Menu(menu)
menu.add_cascade(label="Language", menu=language_menu)

source_language_var = tk.StringVar()
target_language_var = tk.StringVar()

source_menu = tk.Menu(language_menu)
language_menu.add_cascade(label="Source", menu=source_menu)
target_menu = tk.Menu(language_menu)
language_menu.add_cascade(label="Target", menu=target_menu)

# Define language codes (You can extend this list)
languages = [
    ("English", "en"),
    ("French", "fr"),
    ("German", "de"),
    # Add more languages here

for language, code in languages:
    source_menu.add_radiobutton(label=language, variable=source_language_var, value=code)
    target_menu.add_radiobutton(label=language, variable=target_language_var, value=code)

# Create text fields
source_text = tk.Text(root, width=40, height=10)
source_text.grid(row=0, column=0, padx=5, pady=5)

translated_text = tk.Text(root, width=40, height=10)
translated_text.grid(row=0, column=1, padx=5, pady=5)

# Create Translate
translate_button = tk.Button(root, text="Translate", command=translate_and_speak)
translate_button.grid(row=1, column=0, columnspan=2, pady=5)

# Start the GUI application

Comments on 'The Current State of Translation Services: A Visual Overview' (0)

Leave a Reply