Spaces:
Running
Running
Update audio.py
Browse files
audio.py
CHANGED
|
@@ -6,15 +6,13 @@ import resampy
|
|
| 6 |
from hparams import hparams as hp
|
| 7 |
|
| 8 |
def load_wav(path, sr):
|
| 9 |
-
"""
|
| 10 |
-
Load a WAV file and resample it using scipy + resampy.
|
| 11 |
-
"""
|
| 12 |
orig_sr, audio = wavfile.read(path)
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
| 15 |
if audio.dtype.kind == 'i':
|
| 16 |
-
|
| 17 |
-
audio = audio.astype(np.float32) / max_val
|
| 18 |
else:
|
| 19 |
audio = audio.astype(np.float32)
|
| 20 |
|
|
|
|
| 6 |
from hparams import hparams as hp
|
| 7 |
|
| 8 |
def load_wav(path, sr):
|
|
|
|
|
|
|
|
|
|
| 9 |
orig_sr, audio = wavfile.read(path)
|
| 10 |
|
| 11 |
+
if len(audio) < 100: # Arbitrary threshold (can be higher for safety)
|
| 12 |
+
raise ValueError(f"Input audio too short: {len(audio)} samples")
|
| 13 |
+
|
| 14 |
if audio.dtype.kind == 'i':
|
| 15 |
+
audio = audio.astype(np.float32) / np.iinfo(audio.dtype).max
|
|
|
|
| 16 |
else:
|
| 17 |
audio = audio.astype(np.float32)
|
| 18 |
|