Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
mariesig commited on
Commit ·
03a5049
1
Parent(s): 4e945b9
replace soundfile with librosa
Browse files- offline_pipeline.py +10 -9
offline_pipeline.py
CHANGED
|
@@ -3,7 +3,7 @@ from typing import Any
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
-
import
|
| 7 |
|
| 8 |
from constants import APP_TMP_DIR, STREAMER_CLASSES
|
| 9 |
from hf_dataset_utils import get_audio, get_transcript
|
|
@@ -166,9 +166,7 @@ def run_offline_pipeline(
|
|
| 166 |
if sample is None or len(sample) == 0:
|
| 167 |
gr.Warning("No audio to enhance. Please upload a file first.")
|
| 168 |
return _empty_pipeline_result(sample_id)
|
| 169 |
-
|
| 170 |
-
sample = np.asarray(sample, dtype=np.float32).flatten()
|
| 171 |
-
|
| 172 |
_safe_progress(progress, 0.05, "Initializing enhancement...")
|
| 173 |
chunk_size = _init_sdk(sample_rate, enhancement_level)
|
| 174 |
|
|
@@ -249,10 +247,11 @@ def load_local_file(
|
|
| 249 |
raise ValueError("Uploaded file exceeds the 5 MB size limit.")
|
| 250 |
|
| 251 |
new_sample_stem = os.path.splitext(os.path.basename(sample_path))[0]
|
| 252 |
-
y, sample_rate =
|
|
|
|
|
|
|
| 253 |
if normalize:
|
| 254 |
y = normalize_lufs(y, sample_rate)
|
| 255 |
-
|
| 256 |
gradio_audio = to_gradio_audio(y, sample_rate)
|
| 257 |
return y, new_sample_stem, gradio_audio, sample_rate
|
| 258 |
|
|
@@ -268,9 +267,11 @@ def load_file_from_dataset(
|
|
| 268 |
|
| 269 |
try:
|
| 270 |
y, sample_rate = get_audio(sample_id, prefix="mix")
|
| 271 |
-
y_for_gradio = to_gradio_audio(y, sample_rate)
|
| 272 |
except Exception as e:
|
| 273 |
gr.Warning(str(e))
|
| 274 |
raise
|
| 275 |
-
|
| 276 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import gradio as gr
|
| 5 |
import numpy as np
|
| 6 |
+
import librosa
|
| 7 |
|
| 8 |
from constants import APP_TMP_DIR, STREAMER_CLASSES
|
| 9 |
from hf_dataset_utils import get_audio, get_transcript
|
|
|
|
| 166 |
if sample is None or len(sample) == 0:
|
| 167 |
gr.Warning("No audio to enhance. Please upload a file first.")
|
| 168 |
return _empty_pipeline_result(sample_id)
|
| 169 |
+
|
|
|
|
|
|
|
| 170 |
_safe_progress(progress, 0.05, "Initializing enhancement...")
|
| 171 |
chunk_size = _init_sdk(sample_rate, enhancement_level)
|
| 172 |
|
|
|
|
| 247 |
raise ValueError("Uploaded file exceeds the 5 MB size limit.")
|
| 248 |
|
| 249 |
new_sample_stem = os.path.splitext(os.path.basename(sample_path))[0]
|
| 250 |
+
y, sample_rate = librosa.load(sample_path, sr=None, mono=True)
|
| 251 |
+
sample_rate = int(sample_rate)
|
| 252 |
+
y = np.asarray(y, dtype=np.float32)
|
| 253 |
if normalize:
|
| 254 |
y = normalize_lufs(y, sample_rate)
|
|
|
|
| 255 |
gradio_audio = to_gradio_audio(y, sample_rate)
|
| 256 |
return y, new_sample_stem, gradio_audio, sample_rate
|
| 257 |
|
|
|
|
| 267 |
|
| 268 |
try:
|
| 269 |
y, sample_rate = get_audio(sample_id, prefix="mix")
|
|
|
|
| 270 |
except Exception as e:
|
| 271 |
gr.Warning(str(e))
|
| 272 |
raise
|
| 273 |
+
y = np.asarray(y, dtype=np.float32)
|
| 274 |
+
if y.ndim > 1:
|
| 275 |
+
y = np.mean(y, axis=0)
|
| 276 |
+
gradio_audio = to_gradio_audio(y, sample_rate)
|
| 277 |
+
return gradio_audio, y, new_sample_stem, sample_rate
|