reallynicejam commited on
Commit
844c0df
1 Parent(s): 070da69

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -1,11 +1,25 @@
1
  import gradio as gr
2
- def pass_audio(audio):
3
- return audio
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  gr.Interface(
6
- fn=pass_audio,
7
  inputs=gr.Audio(source="microphone", type="file", label="Speak something"),
8
- outputs=gr.Audio(type="file", label="Your Recorded Audio"),
9
  live=True
10
  ).launch()
11
- gr.load("models/facebook/xm_transformer_s2ut_hk-en").launch()
 
1
  import gradio as gr
2
+ import requests
3
+ from io import BytesIO
4
+ from pydub import AudioSegment
5
+
6
+ def translate_audio_to_audio(audio):
7
+ # Send the audio data to the translation model
8
+ translation_response = requests.post(
9
+ "https://api-inference.huggingface.co/models/facebook/xm_transformer_s2ut_hk-en",
10
+ files={"file": audio},
11
+ )
12
+
13
+ # Get the translated audio from the response
14
+ translated_audio_bytes = translation_response.content
15
+ translated_audio = AudioSegment.from_file(BytesIO(translated_audio_bytes))
16
+
17
+ return translated_audio
18
 
19
  gr.Interface(
20
+ fn=translate_audio_to_audio,
21
  inputs=gr.Audio(source="microphone", type="file", label="Speak something"),
22
+ outputs=gr.Audio(type="file", label="Translated Audio"),
23
  live=True
24
  ).launch()
25
+