Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,24 +18,11 @@ def query(api_url, payload):
|
|
18 |
return response.json()
|
19 |
|
20 |
# Define the function to translate speech
|
21 |
-
def translate_speech(
|
22 |
-
print(f"Type of audio: {type(
|
23 |
-
|
24 |
-
# audio is a tuple (np.ndarray, int), we need to save it as a file
|
25 |
-
sample_rate, audio_data = audio
|
26 |
-
if isinstance(audio_data, np.ndarray) and len(audio_data.shape) == 1: # if audio_data is 1D, reshape it to 2D
|
27 |
-
audio_data = np.reshape(audio_data, (-1, 1))
|
28 |
-
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as f:
|
29 |
-
sf.write(f, audio_data, sample_rate)
|
30 |
-
audio_file = f.name
|
31 |
-
|
32 |
-
# Convert the WAV file to MP3
|
33 |
-
audio_segment = AudioSegment.from_wav(audio_file)
|
34 |
-
mp3_file = audio_file.replace(".wav", ".mp3")
|
35 |
-
audio_segment.export(mp3_file, format="mp3")
|
36 |
|
37 |
# Use the ASR pipeline to transcribe the audio
|
38 |
-
with open(
|
39 |
data = f.read()
|
40 |
response = requests.post(ASR_API_URL, headers=headers, data=data)
|
41 |
output = response.json()
|
@@ -67,7 +54,7 @@ def translate_speech(audio):
|
|
67 |
# Define the Gradio interface
|
68 |
iface = gr.Interface(
|
69 |
fn=translate_speech,
|
70 |
-
inputs=gr.inputs.
|
71 |
outputs=gr.outputs.Audio(type="numpy"),
|
72 |
title="Hausa to English Translation",
|
73 |
description="Realtime demo for Hausa to English translation using speech recognition and text-to-speech synthesis."
|
|
|
18 |
return response.json()
|
19 |
|
20 |
# Define the function to translate speech
|
21 |
+
def translate_speech(audio_file):
|
22 |
+
print(f"Type of audio: {type(audio_file)}, Value of audio: {audio_file}") # Debug line
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
# Use the ASR pipeline to transcribe the audio
|
25 |
+
with open(audio_file, "rb") as f:
|
26 |
data = f.read()
|
27 |
response = requests.post(ASR_API_URL, headers=headers, data=data)
|
28 |
output = response.json()
|
|
|
54 |
# Define the Gradio interface
|
55 |
iface = gr.Interface(
|
56 |
fn=translate_speech,
|
57 |
+
inputs=gr.inputs.File(type="file"), # Change this line
|
58 |
outputs=gr.outputs.Audio(type="numpy"),
|
59 |
title="Hausa to English Translation",
|
60 |
description="Realtime demo for Hausa to English translation using speech recognition and text-to-speech synthesis."
|