rohitptnk commited on
Commit
2ab10af
·
1 Parent(s): aa54184

Modify code to include gradio interface

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -1,22 +1,32 @@
 
1
  from my_transcribe import transcribe_audio_locally
2
  from my_translate import translate_text
3
  from my_tts import text_to_speech
4
 
5
- def voice_to_voice(audio_file_path):
6
  # Step 1: Transcribe
7
- result = transcribe_audio_locally(audio_file_path, model_size="base")
8
  source_text = result["text"]
9
- print("Transcribed:", source_text)
10
 
11
  # Step 2: Translate
12
  translated = translate_text(source_text, from_lang="en", to_lang="hi")
13
- print("Translated:", translated)
14
 
15
- # Step 3: Text to Speech
16
  output_audio_path = text_to_speech(translated, "v2/hi_speaker_2")
17
- print("Saved translated speech to:", output_audio_path)
18
 
19
- return output_audio_path
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  if __name__ == "__main__":
22
- voice_to_voice("Input Audio Sample.wav")
 
1
+ import gradio as gr
2
  from my_transcribe import transcribe_audio_locally
3
  from my_translate import translate_text
4
  from my_tts import text_to_speech
5
 
6
+ def voice_to_voice(audio):
7
  # Step 1: Transcribe
8
+ result = transcribe_audio_locally(audio, model_size="base")
9
  source_text = result["text"]
 
10
 
11
  # Step 2: Translate
12
  translated = translate_text(source_text, from_lang="en", to_lang="hi")
 
13
 
14
+ # Step 3: TTS
15
  output_audio_path = text_to_speech(translated, "v2/hi_speaker_2")
 
16
 
17
+ return output_audio_path, source_text, translated
18
+
19
+ iface = gr.Interface(
20
+ fn=voice_to_voice,
21
+ inputs=gr.Audio(type="filepath", label="Upload English Audio"),
22
+ outputs=[
23
+ gr.Audio(label="Translated Audio (Hindi)"),
24
+ gr.Textbox(label="Transcribed Text (English)"),
25
+ gr.Textbox(label="Translated Text (Hindi)"),
26
+ ],
27
+ title="Voice-to-Voice Translator",
28
+ description="Upload an English audio file. It will be transcribed, translated to Hindi, and synthesized as speech."
29
+ )
30
 
31
  if __name__ == "__main__":
32
+ iface.launch()