Spaces:
Sleeping
Sleeping
File size: 1,614 Bytes
be1c4be |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
import gradio as gr
from gtts import gTTS
import os
# Simple German-English learning dataset
phrases = {
"Hello": "Hallo",
"Good Morning": "Guten Morgen",
"Thank you": "Danke",
"Good Night": "Gute Nacht",
"How are you?": "Wie geht es dir?",
"I love Germany": "Ich liebe Deutschland",
"What is your name?": "Wie heißt du?",
"Goodbye": "Auf Wiedersehen",
"Yes": "Ja",
"No": "Nein"
}
# Function to get translation
def translate_to_german(english_text):
if english_text in phrases:
german = phrases[english_text]
return german
else:
return "Not found in dictionary."
# Function to speak German
def speak_german(text):
german = translate_to_german(text)
if german != "Not found in dictionary.":
tts = gTTS(german, lang="de")
audio_file = "german_audio.mp3"
tts.save(audio_file)
return german, audio_file
else:
return german, None
# UI Layout
with gr.Blocks(title="🇩🇪 Learn German with Dr. Hidayatullah Mahar") as demo:
gr.Markdown("## 🇩🇪 Learn German\n### Translate common English phrases into German and hear pronunciation.")
english_input = gr.Dropdown(choices=list(phrases.keys()), label="Select English Phrase")
translate_btn = gr.Button("Translate & Speak")
output_text = gr.Textbox(label="German Translation")
output_audio = gr.Audio(label="German Pronunciation")
translate_btn.click(fn=speak_german, inputs=english_input, outputs=[output_text, output_audio])
gr.Markdown("**Developed by Dr. Hidayatullah Mahar**")
demo.launch() |