Spaces:
Sleeping
Sleeping
Add application file
Browse files
app.py
CHANGED
@@ -21,7 +21,6 @@ import logging
|
|
21 |
import time
|
22 |
import traceback
|
23 |
import numpy as np
|
24 |
-
import yt_dlp
|
25 |
from pathlib import Path
|
26 |
from huggingface_hub import hf_hub_download
|
27 |
from typing import Dict, Tuple
|
@@ -43,6 +42,35 @@ STEM_NAMING = {
|
|
43 |
"Bass": "Bassless",
|
44 |
}
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
class MDXModel:
|
47 |
def __init__(
|
48 |
self,
|
|
|
21 |
import time
|
22 |
import traceback
|
23 |
import numpy as np
|
|
|
24 |
from pathlib import Path
|
25 |
from huggingface_hub import hf_hub_download
|
26 |
from typing import Dict, Tuple
|
|
|
42 |
"Bass": "Bassless",
|
43 |
}
|
44 |
|
45 |
+
|
46 |
+
def convert_to_stereo_and_wav(audio_path: Path) -> Path:
|
47 |
+
# loading takes time since resampling at 44100 Hz
|
48 |
+
wave, sr = librosa.load(str(audio_path), mono=False, sr=44100)
|
49 |
+
|
50 |
+
# check if mono
|
51 |
+
if type(wave[0]) != np.ndarray or audio_path.suffix != ".wav": # noqa
|
52 |
+
stereo_path = audio_path.with_name(audio_path.stem + "_stereo.wav")
|
53 |
+
|
54 |
+
command = shlex.split(
|
55 |
+
f'ffmpeg -y -loglevel error -i "{str(audio_path)}" -ac 2 -f wav "{str(stereo_path)}"'
|
56 |
+
)
|
57 |
+
sub_params = {
|
58 |
+
"stdout": subprocess.PIPE,
|
59 |
+
"stderr": subprocess.PIPE,
|
60 |
+
"creationflags": subprocess.CREATE_NO_WINDOW
|
61 |
+
if sys.platform == "win32"
|
62 |
+
else 0,
|
63 |
+
}
|
64 |
+
process_wav = subprocess.Popen(command, **sub_params)
|
65 |
+
output, errors = process_wav.communicate()
|
66 |
+
if process_wav.returncode != 0 or not stereo_path.exists():
|
67 |
+
raise Exception("Error processing audio to stereo wav")
|
68 |
+
|
69 |
+
return stereo_path
|
70 |
+
else:
|
71 |
+
return Path(audio_path)
|
72 |
+
|
73 |
+
|
74 |
class MDXModel:
|
75 |
def __init__(
|
76 |
self,
|