Update audio.py
Browse files
audio.py
CHANGED
|
@@ -1,4 +1,27 @@
|
|
| 1 |
import librosa
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
import librosa.filters
|
| 3 |
import numpy as np
|
| 4 |
|
|
|
|
| 1 |
import librosa
|
| 2 |
+
import os
|
| 3 |
+
import numpy as np
|
| 4 |
+
import soundfile as sf
|
| 5 |
+
|
| 6 |
+
# Monkey-patch librosa.util.find_files to avoid librosa.util.files (which imports pkg_resources)
|
| 7 |
+
if hasattr(librosa, "util") and hasattr(librosa.util, "find_files"):
|
| 8 |
+
# If it's already there, we leave it alone
|
| 9 |
+
pass
|
| 10 |
+
else:
|
| 11 |
+
def _simple_find_files(path, ext=None):
|
| 12 |
+
if ext is None:
|
| 13 |
+
ext = [".wav", ".mp3", ".flac"]
|
| 14 |
+
if isinstance(ext, str):
|
| 15 |
+
ext = [ext]
|
| 16 |
+
out = []
|
| 17 |
+
for root, _, files in os.walk(path):
|
| 18 |
+
for f in files:
|
| 19 |
+
if any(f.lower().endswith(e) for e in ext):
|
| 20 |
+
out.append(os.path.join(root, f))
|
| 21 |
+
return out
|
| 22 |
+
|
| 23 |
+
if hasattr(librosa, "util"):
|
| 24 |
+
librosa.util.find_files = _simple_find_files
|
| 25 |
import librosa.filters
|
| 26 |
import numpy as np
|
| 27 |
|