Download rvc/lib/utils.py from vickyalee/Applio9: direct link, hf CLI and curl.
- Browser
- Download file 939 Bytes
-
https://huggingface.co/spaces/vickyalee/Applio9/resolve/main/rvc/lib/utils.py
- Command line
-
hf download hf://spaces/vickyalee/Applio9/rvc/lib/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/vickyalee/Applio9/resolve/main/rvc/lib/utils.py
939 Bytes
| import ffmpeg | |
| import numpy as np | |
| import re | |
| import unicodedata | |
| def load_audio(file, sampling_rate): | |
| try: | |
| file = file.strip(" ").strip('"').strip("\n").strip('"').strip(" ") | |
| out, _ = ( | |
| ffmpeg.input(file, threads=0) | |
| .output("-", format="f32le", acodec="pcm_f32le", ac=1, ar=sampling_rate) | |
| .run(cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True) | |
| ) | |
| except Exception as error: | |
| raise RuntimeError(f"Failed to load audio: {error}") | |
| return np.frombuffer(out, np.float32).flatten() | |
| def format_title(title): | |
| formatted_title = ( | |
| unicodedata.normalize("NFKD", title).encode("ascii", "ignore").decode("utf-8") | |
| ) | |
| formatted_title = re.sub(r"[\u2500-\u257F]+", "", formatted_title) | |
| formatted_title = re.sub(r"[^\w\s.-]", "", formatted_title) | |
| formatted_title = re.sub(r"\s+", "_", formatted_title) | |
| return formatted_title | |