Spaces:
Sleeping
Sleeping
| 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() |