Spaces:
Sleeping
Sleeping
Fix EncoderASR.transcribe_batch() error
Browse files
app.py
CHANGED
|
@@ -22,12 +22,16 @@ def transcribe(audio):
|
|
| 22 |
# Load audio
|
| 23 |
waveform, sample_rate = torchaudio.load(audio)
|
| 24 |
|
| 25 |
-
# Ensure correct sample rate (16kHz expected)
|
| 26 |
if sample_rate != 16000:
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
# Transcribe
|
| 30 |
-
transcription = asr_model.transcribe_batch(waveform)
|
| 31 |
return transcription[0]
|
| 32 |
|
| 33 |
except Exception as e:
|
|
|
|
| 22 |
# Load audio
|
| 23 |
waveform, sample_rate = torchaudio.load(audio)
|
| 24 |
|
| 25 |
+
# Ensure correct sample rate (16kHz expected by the model)
|
| 26 |
if sample_rate != 16000:
|
| 27 |
+
resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)
|
| 28 |
+
waveform = resampler(waveform)
|
| 29 |
+
|
| 30 |
+
# Compute waveform length in seconds relative to batch size
|
| 31 |
+
wav_lens = torch.tensor([waveform.shape[1] / 16000], dtype=torch.float32)
|
| 32 |
|
| 33 |
# Transcribe
|
| 34 |
+
transcription = asr_model.transcribe_batch(waveform, wav_lens)
|
| 35 |
return transcription[0]
|
| 36 |
|
| 37 |
except Exception as e:
|