Sapna36 commited on
Commit
c2b4ff1
·
verified ·
1 Parent(s): 8181bb4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -8
app.py CHANGED
@@ -14,9 +14,10 @@ def voice_to_voice(audio_file):
14
  else:
15
  transcript_text = transcript.text
16
 
17
- translations = translate_text(transcript_text)
18
- audio_paths = [text_to_speech(text) for text in translations]
19
- return tuple(audio_paths + translations)
 
20
 
21
  def transcribe_audio(audio_file):
22
  aai.settings.api_key = os.getenv("ASSEMBLYAI_API_KEY")
@@ -24,8 +25,8 @@ def transcribe_audio(audio_file):
24
  return transcriber.transcribe(audio_file)
25
 
26
  def translate_text(text):
27
- languages = ["ru", "tr", "sv", "de", "es", "ja"]
28
- return [Translator(from_lang="en", to_lang=lan).translate(text) for lan in languages]
29
 
30
  def text_to_speech(text):
31
  client = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))
@@ -49,10 +50,9 @@ audio_input = gr.Audio(sources=["microphone"], type="filepath", show_download_bu
49
  demo = gr.Interface(
50
  fn=voice_to_voice,
51
  inputs=audio_input,
52
- outputs=[gr.Audio(label=lang) for lang in ["Russian", "Turkish", "Swedish", "German", "Spanish", "Japanese"]] +
53
- [gr.Textbox(label=lang) for lang in ["Russian", "Turkish", "Swedish", "German", "Spanish", "Japanese"]],
54
  title="Voice-to-Voice Translator",
55
- description="Record yourself in English and get voice translations in multiple languages."
56
  )
57
 
58
  if __name__ == "__main__":
 
14
  else:
15
  transcript_text = transcript.text
16
 
17
+ translation = translate_text(transcript_text)
18
+ audio_path = text_to_speech(translation)
19
+
20
+ return audio_path, translation
21
 
22
  def transcribe_audio(audio_file):
23
  aai.settings.api_key = os.getenv("ASSEMBLYAI_API_KEY")
 
25
  return transcriber.transcribe(audio_file)
26
 
27
  def translate_text(text):
28
+ translator = Translator(from_lang="en", to_lang="es") # Translate to Spanish
29
+ return translator.translate(text)
30
 
31
  def text_to_speech(text):
32
  client = ElevenLabs(api_key=os.getenv("ELEVENLABS_API_KEY"))
 
50
  demo = gr.Interface(
51
  fn=voice_to_voice,
52
  inputs=audio_input,
53
+ outputs=[gr.Audio(label="Spanish"), gr.Textbox(label="Translated Text (Spanish)")],
 
54
  title="Voice-to-Voice Translator",
55
+ description="Record yourself in English and get the translation in Spanish with voice output."
56
  )
57
 
58
  if __name__ == "__main__":