Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ import gradio as gr
|
|
| 2 |
from transformers import pipeline, AutoTokenizer
|
| 3 |
from huggingsound import SpeechRecognitionModel
|
| 4 |
import numpy as np
|
|
|
|
|
|
|
| 5 |
|
| 6 |
# Load the model for speech recognition
|
| 7 |
model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-large-xlsr-53-english")
|
|
@@ -16,9 +18,16 @@ def translate_speech(audio_data_tuple):
|
|
| 16 |
# Extract the audio data from the tuple
|
| 17 |
sample_rate, audio_data = audio_data_tuple
|
| 18 |
|
| 19 |
-
#
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
# Use the translation pipeline to translate the transcription
|
| 24 |
translated_text = translator(output, return_tensors="pt")
|
|
|
|
| 2 |
from transformers import pipeline, AutoTokenizer
|
| 3 |
from huggingsound import SpeechRecognitionModel
|
| 4 |
import numpy as np
|
| 5 |
+
import soundfile as sf
|
| 6 |
+
import tempfile
|
| 7 |
|
| 8 |
# Load the model for speech recognition
|
| 9 |
model = SpeechRecognitionModel("jonatasgrosman/wav2vec2-large-xlsr-53-english")
|
|
|
|
| 18 |
# Extract the audio data from the tuple
|
| 19 |
sample_rate, audio_data = audio_data_tuple
|
| 20 |
|
| 21 |
+
# Save the audio data to a temporary file
|
| 22 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=True) as temp_audio_file:
|
| 23 |
+
sf.write(temp_audio_file.name, audio_data, sample_rate)
|
| 24 |
+
|
| 25 |
+
# Use the speech recognition model to transcribe the audio
|
| 26 |
+
output = model.transcribe([temp_audio_file.name])
|
| 27 |
+
print(f"Output: {output}") # Print the output to see what it contains
|
| 28 |
+
|
| 29 |
+
# ... (rest of your code)
|
| 30 |
+
|
| 31 |
|
| 32 |
# Use the translation pipeline to translate the transcription
|
| 33 |
translated_text = translator(output, return_tensors="pt")
|