Update app.py
Browse files
app.py
CHANGED
|
@@ -13,24 +13,17 @@ for m in models.values():
|
|
| 13 |
m.model.generation_config.input_ids = m.model.generation_config.forced_decoder_ids
|
| 14 |
m.model.generation_config.forced_decoder_ids = None
|
| 15 |
|
| 16 |
-
|
| 17 |
def ensure_mono_16k(audio_path):
|
| 18 |
-
"""
|
| 19 |
waveform, sr = torchaudio.load(audio_path)
|
| 20 |
-
|
| 21 |
-
# Convert to mono if necessary
|
| 22 |
if waveform.shape[0] > 1:
|
| 23 |
waveform = waveform.mean(dim=0, keepdim=True)
|
| 24 |
-
|
| 25 |
-
# Resample to 16kHz if necessary
|
| 26 |
if sr != 16000:
|
| 27 |
resampler = torchaudio.transforms.Resample(sr, 16000)
|
| 28 |
waveform = resampler(waveform)
|
| 29 |
sr = 16000
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
torchaudio.save(tmp_path, waveform, sr)
|
| 33 |
-
return tmp_path
|
| 34 |
|
| 35 |
def trim_leading_silence(waveform, sr, keep_ms=100, threshold=0.01):
|
| 36 |
"""
|
|
|
|
| 13 |
m.model.generation_config.input_ids = m.model.generation_config.forced_decoder_ids
|
| 14 |
m.model.generation_config.forced_decoder_ids = None
|
| 15 |
|
|
|
|
| 16 |
def ensure_mono_16k(audio_path):
|
| 17 |
+
"""Convert audio to mono + 16 kHz"""
|
| 18 |
waveform, sr = torchaudio.load(audio_path)
|
|
|
|
|
|
|
| 19 |
if waveform.shape[0] > 1:
|
| 20 |
waveform = waveform.mean(dim=0, keepdim=True)
|
|
|
|
|
|
|
| 21 |
if sr != 16000:
|
| 22 |
resampler = torchaudio.transforms.Resample(sr, 16000)
|
| 23 |
waveform = resampler(waveform)
|
| 24 |
sr = 16000
|
| 25 |
+
return waveform, sr
|
| 26 |
+
|
|
|
|
|
|
|
| 27 |
|
| 28 |
def trim_leading_silence(waveform, sr, keep_ms=100, threshold=0.01):
|
| 29 |
"""
|