Update app.py
Browse files
app.py
CHANGED
@@ -13,15 +13,11 @@ translator = pipeline("text2text-generation", model="Baghdad99/saad-hausa-text-t
|
|
13 |
tts = pipeline("text-to-speech", model="Baghdad99/english_voice_tts")
|
14 |
|
15 |
# Define the function to translate speech
|
16 |
-
def translate_speech(
|
17 |
-
print(f"Type of audio: {type(
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
# Convert the audio to mono and get the raw data
|
23 |
-
audio = audio.set_channels(1)
|
24 |
-
audio_data = np.array(audio.get_array_of_samples())
|
25 |
|
26 |
# Use the speech recognition pipeline to transcribe the audio
|
27 |
output = pipe(audio_data)
|
@@ -65,16 +61,13 @@ def translate_speech(audio_file):
|
|
65 |
|
66 |
return 16000, synthesised_speech
|
67 |
|
68 |
-
|
69 |
-
|
70 |
# Define the Gradio interface
|
71 |
iface = gr.Interface(
|
72 |
fn=translate_speech,
|
73 |
-
inputs=gr.inputs.Audio(
|
74 |
outputs=gr.outputs.Audio(type="numpy"),
|
75 |
title="Hausa to English Translation",
|
76 |
description="Realtime demo for Hausa to English translation using speech recognition and text-to-speech synthesis."
|
77 |
)
|
78 |
|
79 |
iface.launch()
|
80 |
-
|
|
|
13 |
tts = pipeline("text-to-speech", model="Baghdad99/english_voice_tts")
|
14 |
|
15 |
# Define the function to translate speech
|
16 |
+
def translate_speech(audio_data_tuple):
|
17 |
+
print(f"Type of audio: {type(audio_data_tuple)}, Value of audio: {audio_data_tuple}") # Debug line
|
18 |
|
19 |
+
# Extract the audio data from the tuple
|
20 |
+
sample_rate, audio_data = audio_data_tuple
|
|
|
|
|
|
|
|
|
21 |
|
22 |
# Use the speech recognition pipeline to transcribe the audio
|
23 |
output = pipe(audio_data)
|
|
|
61 |
|
62 |
return 16000, synthesised_speech
|
63 |
|
|
|
|
|
64 |
# Define the Gradio interface
|
65 |
iface = gr.Interface(
|
66 |
fn=translate_speech,
|
67 |
+
inputs=gr.inputs.Audio(source="microphone"), # Change this line
|
68 |
outputs=gr.outputs.Audio(type="numpy"),
|
69 |
title="Hausa to English Translation",
|
70 |
description="Realtime demo for Hausa to English translation using speech recognition and text-to-speech synthesis."
|
71 |
)
|
72 |
|
73 |
iface.launch()
|
|