Translator-Main

Home   »   Translator-Main

############################### Tkinter is used to make a GUI for translating ###############################
import tkinter as tk

# creating a new tkinter window 
master = tk.Tk() 

canvas = tk.Canvas(master, width = 400, height = 300)
canvas.pack()

l1 = tk.Label(master, text = "From")
canvas.create_window(100, 20, window=l1)

l2 = tk.Label(master, text = "To")
canvas.create_window(300, 20, window=l2)

#################################################################
fl = ask("Mention the language you are speaking in")
f = d.get(fl)
e1 = tk.Entry (master)
e1.insert(10, f)
canvas.create_window(100, 50, window=e1)

# creating arrow in the canvas
canvas.create_line(170, 50, 230, 50, arrow=tk.LAST)

tl = ask("Mention the language you want the translation in")
t = d.get(tl)
e2 = tk.Entry (master)
e2.insert(10, t)
canvas.create_window(300, 50, window=e2)

l3 = tk.Label(master, text = "Spoken Sentence")
canvas.create_window(100, 100, window=l3)

l4 = tk.Label(master, text = "Translated Sentence")
canvas.create_window(300, 100, window=l4)
#################################################################
speak("Speak the sentence you want to translate")
text = hear(fl)
e3 = tk.Entry (master, text = text)
e3.insert(10,text)
canvas.create_window(100, 130, window=e3)

canvas.create_line(170, 130, 230, 130, arrow=tk.LAST)
##################################################################

################# Start Translating ##################
from googletrans import Translator
translator = Translator()

dt1 = translator.detect(text) # determine the language of the text with detect()
print(dt1)

#translated = translated = translator.translate(text) # translate the language to English (default)
#print(translated.text)

translated = translator.translate(text, src=fl, dest=tl) # translate the source language to destination language
print(translated.text)

text1 = translated.text
e4 = tk.Entry (master, text = text1)
e4.insert(10, text1)
canvas.create_window(300, 130, window=e4)

master.mainloop()

Leave a Reply

Your email address will not be published. Required fields are marked *