Update app.py
Browse files
app.py
CHANGED
@@ -17,17 +17,15 @@ def translate_speech(audio_input):
|
|
17 |
# Load the audio file as a floating point time series
|
18 |
audio_data, sample_rate = librosa.load(audio_input, sr=None)
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
# Decode the predicted IDs to get the transcription
|
30 |
-
transcription = pipe.tokenizer.decode(pred_ids)
|
31 |
|
32 |
# Use the translation pipeline to translate the transcription
|
33 |
translated_text = translator(transcription, return_tensors="pt")
|
@@ -58,6 +56,7 @@ def translate_speech(audio_input):
|
|
58 |
|
59 |
return 16000, synthesised_speech
|
60 |
|
|
|
61 |
# Define the Gradio interface
|
62 |
iface = gr.Interface(
|
63 |
fn=translate_speech,
|
|
|
17 |
# Load the audio file as a floating point time series
|
18 |
audio_data, sample_rate = librosa.load(audio_input, sr=None)
|
19 |
|
20 |
+
# Use the speech recognition pipeline to transcribe the audio
|
21 |
+
output = pipe(audio_data)
|
22 |
|
23 |
+
# Check if the output contains 'text'
|
24 |
+
if 'text' in output:
|
25 |
+
transcription = output["text"]
|
26 |
+
else:
|
27 |
+
print("The output does not contain 'text'")
|
28 |
+
return
|
|
|
|
|
29 |
|
30 |
# Use the translation pipeline to translate the transcription
|
31 |
translated_text = translator(transcription, return_tensors="pt")
|
|
|
56 |
|
57 |
return 16000, synthesised_speech
|
58 |
|
59 |
+
|
60 |
# Define the Gradio interface
|
61 |
iface = gr.Interface(
|
62 |
fn=translate_speech,
|