Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +35 -0
- requirements.txt +3 -0
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import pipeline
|
4 |
+
|
5 |
+
# Load models
|
6 |
+
speech_to_text = pipeline("automatic-speech-recognition", model="openai/whisper-small")
|
7 |
+
translation = pipeline("translation", model="Helsinki-NLP/opus-mt-hi-en")
|
8 |
+
text_to_speech = pipeline("text-to-speech", model="espnet/kan-bayashi_ljspeech_vits")
|
9 |
+
|
10 |
+
def translate_speech(audio):
|
11 |
+
# Step 1: Hindi speech to Hindi text
|
12 |
+
hindi_text = speech_to_text(audio)["text"]
|
13 |
+
|
14 |
+
# Step 2: Hindi text to English translation
|
15 |
+
english_text = translation(hindi_text)[0]["translation_text"]
|
16 |
+
|
17 |
+
# Step 3: English text to speech
|
18 |
+
english_speech = text_to_speech(english_text)["audio"]
|
19 |
+
|
20 |
+
return hindi_text, english_text, (48000, english_speech)
|
21 |
+
|
22 |
+
# Gradio Interface
|
23 |
+
demo = gr.Interface(
|
24 |
+
fn=translate_speech,
|
25 |
+
inputs=gr.Audio(source="microphone", type="filepath"),
|
26 |
+
outputs=[
|
27 |
+
gr.Textbox(label="Hindi Text"),
|
28 |
+
gr.Textbox(label="English Translation"),
|
29 |
+
gr.Audio(label="English Audio")
|
30 |
+
],
|
31 |
+
title="Hindi to English Speech Translator",
|
32 |
+
description="🎤 Speak in Hindi and get the English translation spoken aloud"
|
33 |
+
)
|
34 |
+
|
35 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|
3 |
+
gradio
|