Spaces:
Sleeping
Sleeping
Update librosa/core/__init__.py
Browse files- librosa/core/__init__.py +4 -16
librosa/core/__init__.py
CHANGED
|
@@ -1,15 +1,10 @@
|
|
| 1 |
-
# Minimal librosa.core stub for Spleeter on Python 3.10+
|
| 2 |
-
# Uses TensorFlow STFT/ISTFT backend instead of librosa+numba
|
| 3 |
-
|
| 4 |
import tensorflow as tf
|
| 5 |
import numpy as np
|
| 6 |
|
|
|
|
|
|
|
| 7 |
def stft(y, n_fft=2048, hop_length=512, win_length=2048, center=True, window=None, **kwargs):
|
| 8 |
-
"""
|
| 9 |
-
Minimal STFT stub compatible with Spleeter.
|
| 10 |
-
"""
|
| 11 |
y = tf.convert_to_tensor(y, dtype=tf.float32)
|
| 12 |
-
|
| 13 |
Z = tf.signal.stft(
|
| 14 |
y,
|
| 15 |
frame_length=win_length,
|
|
@@ -18,22 +13,15 @@ def stft(y, n_fft=2048, hop_length=512, win_length=2048, center=True, window=Non
|
|
| 18 |
window_fn=tf.signal.hann_window,
|
| 19 |
pad_end=True
|
| 20 |
)
|
| 21 |
-
|
| 22 |
-
# Convert to numpy safely
|
| 23 |
-
return np.array(Z)
|
| 24 |
-
|
| 25 |
|
| 26 |
|
| 27 |
def istft(Z, hop_length=512, win_length=2048, window=None, **kwargs):
|
| 28 |
Z = tf.convert_to_tensor(Z, dtype=tf.complex64)
|
| 29 |
-
|
| 30 |
audio = tf.signal.inverse_stft(
|
| 31 |
Z,
|
| 32 |
frame_length=win_length,
|
| 33 |
frame_step=hop_length,
|
| 34 |
window_fn=tf.signal.hann_window
|
| 35 |
)
|
| 36 |
-
|
| 37 |
-
return np.array(audio)
|
| 38 |
-
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import tensorflow as tf
|
| 2 |
import numpy as np
|
| 3 |
|
| 4 |
+
tf.config.run_functions_eagerly(True) # Enforce eager execution globally
|
| 5 |
+
|
| 6 |
def stft(y, n_fft=2048, hop_length=512, win_length=2048, center=True, window=None, **kwargs):
|
|
|
|
|
|
|
|
|
|
| 7 |
y = tf.convert_to_tensor(y, dtype=tf.float32)
|
|
|
|
| 8 |
Z = tf.signal.stft(
|
| 9 |
y,
|
| 10 |
frame_length=win_length,
|
|
|
|
| 13 |
window_fn=tf.signal.hann_window,
|
| 14 |
pad_end=True
|
| 15 |
)
|
| 16 |
+
return Z.numpy() # now works in eager mode
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
|
| 19 |
def istft(Z, hop_length=512, win_length=2048, window=None, **kwargs):
|
| 20 |
Z = tf.convert_to_tensor(Z, dtype=tf.complex64)
|
|
|
|
| 21 |
audio = tf.signal.inverse_stft(
|
| 22 |
Z,
|
| 23 |
frame_length=win_length,
|
| 24 |
frame_step=hop_length,
|
| 25 |
window_fn=tf.signal.hann_window
|
| 26 |
)
|
| 27 |
+
return audio.numpy()
|
|
|
|
|
|
|
|
|