Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -70,21 +70,22 @@ def convert_to_wav(filepath):
|
|
70 |
pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'})
|
71 |
|
72 |
@spaces.GPU()
|
73 |
-
def transcribe_audio(filepath, batch_size=16
|
74 |
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
83 |
|
84 |
# --convert to mono
|
85 |
if waveform.ndim > 1:
|
86 |
waveform = waveform[0, :]
|
87 |
-
|
88 |
waveform = waveform.numpy()
|
89 |
|
90 |
start_time = time.time()
|
|
|
70 |
pipe = pipeline("automatic-speech-recognition", model="NbAiLab/nb-whisper-large", chunk_length_s=30, generate_kwargs={'task': 'transcribe', 'language': 'no'})
|
71 |
|
72 |
@spaces.GPU()
|
73 |
+
def transcribe_audio(filepath, batch_size=16):
|
74 |
|
75 |
+
with tempfile.NamedTemporaryFile(suffix=".wav") as temp_audio_file:
|
76 |
+
# Copy the contents of the uploaded audio file to the temporary file
|
77 |
+
temp_audio_file.write(open(audio, "rb").read())
|
78 |
+
temp_audio_file.flush()
|
79 |
+
# Load the audio file using torchaudio
|
80 |
+
waveform, sample_rate = torchaudio.load(temp_audio_file.name)
|
81 |
+
# Resample the audio to 16kHz
|
82 |
+
resampler = torchaudio.transforms.Resample(sample_rate, 16000)
|
83 |
+
waveform = resampler(waveform)
|
84 |
|
85 |
# --convert to mono
|
86 |
if waveform.ndim > 1:
|
87 |
waveform = waveform[0, :]
|
88 |
+
# Convert PyTorch tensor NumPy ndarray
|
89 |
waveform = waveform.numpy()
|
90 |
|
91 |
start_time = time.time()
|