Spaces:
Runtime error
Runtime error
File size: 7,287 Bytes
4e9cd67 213a0d6 4e9cd67 213a0d6 4e9cd67 8c5e44c 4e9cd67 8c5e44c 0046dd1 4e9cd67 0046dd1 4e9cd67 2c00136 4e9cd67 2c00136 4e9cd67 4e7b252 4e9cd67 8c5e44c 4e9cd67 8c5e44c 2c00136 8c5e44c bd660cc 2c00136 8c5e44c 2c00136 8c5e44c 2c00136 8c5e44c 2c00136 8c5e44c bd660cc 8c5e44c 4e9cd67 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
import io
import gradio as gr
import librosa
import numpy as np
import soundfile
import torch
from inference.infer_tool import Svc
import logging
logging.getLogger('numba').setLevel(logging.WARNING)
model_name = "logs/48k/suiji.pth"
config_name = "configs/suiji.json"
svc_model = Svc(model_name, config_name)
sid_map = {
"岁己(本音)": "suiji"
}
def vc_fn(sid, input_audio, vc_transform):
if input_audio is None:
return "请选择或拖入一段音频", None
sampling_rate, audio = input_audio
# print(audio.shape,sampling_rate)
duration = audio.shape[0] / sampling_rate
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
if len(audio.shape) > 1:
audio = librosa.to_mono(audio.transpose(1, 0))
if sampling_rate != 16000:
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=16000)
print(audio.shape)
out_wav_path = io.BytesIO()
soundfile.write(out_wav_path, audio, 16000, format="wav")
out_wav_path.seek(0)
sid = sid_map[sid]
out_audio, out_sr = svc_model.infer(sid, vc_transform, out_wav_path)
_audio = out_audio.cpu().numpy()
return "成功", (48000, _audio)
app = gr.Blocks()
with app:
with gr.Tabs():
with gr.TabItem("歌声音色转换"):
gr.Markdown(value="""
# 强烈建议☝️先看一遍使用说明
## 这是 sovits 3.0 48kHz AI岁己“歌声”音色转换的在线demo
#### 目前模型训练状态:700000steps / 640epochs
#### 如果要训练自己的数据请访问:[项目Github仓库](https://github.com/innnky/so-vits-svc/tree/main)、[教程《svc相关》](https://www.yuque.com/jiuwei-nui3d/qng6eg)
#### 建议参考上方“使用说明”下的教程,在本地使用 inference_main.py 处理,我都写成这样了再小白应该都能搞定
#### 本地推理可调用GPU(cuda),3060Ti 8G可推理一条20(建议) - 30s的音频,过长音频可分割后批量处理
""")
sid = gr.Dropdown(label="音色", choices=["岁己(本音)"], value="岁己(本音)")
vc_input3 = gr.Audio(label="输入音频(长度请控制在30s左右,过长可能会爆内存)")
vc_transform = gr.Number(label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0)
vc_submit = gr.Button("转换", variant="primary")
vc_output1 = gr.Textbox(label="输出日志")
vc_output2 = gr.Audio(label="输出音频(最右侧三个点可以下载)")
vc_submit.click(vc_fn, [sid, vc_input3, vc_transform], [vc_output1, vc_output2])
with gr.TabItem("亿点点使用说明➕保姆级本地部署教程"):
gr.Markdown(value="""
# 强烈建议👇先看一遍使用说明
### 输入的音频一定要是纯净的干音,不要把歌曲直接扔进来
### 长音不太稳,音域不算宽,选曲限制比较大,推荐多试试变调
### 对陈述语气没多大作用,实在没干音库的话,你可以自己唱然后升十几个调慢慢试效果
### 因为训练集来自于录播,所以音色偏本音,前期变调用于匹配音域,后期可以升一个调匹配一下岁己的歌音
# 在本地部署并使用 inference_main.py 处理的保姆级教程:
# 未完工,还在解决装依赖的问题
### 0. 创建一个存放文件的目录,例如 D:\\SUI\\
### 1. 安装所需的软件
1. [miniconda-Python3.8](https://docs.conda.io/en/latest/miniconda.html#windows-installers)(未测试其他Python版本)[点这里可以直接下载](https://repo.anaconda.com/miniconda/Miniconda3-py38_22.11.1-1-Windows-x86_64.exe),Just Me 与 All Users 都行,其余可无脑下一步
2. [git](https://git-scm.com/download/win)(建议使用便携版)[点这里可以直接下载(便携版v2.39.0.2)](https://github.com/git-for-windows/git/releases/download/v2.39.0.windows.2/PortableGit-2.39.0.2-64-bit.7z.exe),路径填 D:\\SUI\\git\\
### 2. 在开始菜单中运行 Anaconda Powershell Prompt 并配置环境(除了工作目录,复制粘贴回车即可)
```
# 切换工作目录
cd D:\\SUI\\
# 拉取仓库
.\\git\\bin\\git lfs clone https://huggingface.co/spaces/Miuzarte/SUI-svc-3.0
# 切换工作目录至仓库内
cd D:\\SUI\\SUI-svc-3.0\\
# 创建并激活环境
conda create -n sovits python=3.8 -y
conda activate sovits
# 更换国内清华源
conda config --set show_channel_urls yes
conda config --remove-key channels
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# 下面这一条给 NVIDIA 用户
conda install pytorch==1.12.1 torchvision==0.13.1 torchaudio==0.12.1 cudatoolkit=11.3 -y
# 安装其余依赖(如果pip报SSL相关错误请关闭科学上网)
pip install -r requirements_local.txt
```
至此环境配置完成,关闭该终端窗口(方便我写下一步)
### 3. 歌声音色转换
1. 运行 Anaconda Powershell Prompt 切换工作目录并激活环境
```
cd D:\\SUI\\SUI-svc-3.0\\
conda activate sovits
```
2. 在 SUI-svc-3.0\\raw\\ 文件夹中放入需要转换的音频(wav格式),8G显存的情况下不建议每条音频超过30s(不包括无声部分),过长会爆显存导致处理时间超级加倍甚至直接报错
3. 编辑 SUI-svc-3.0\\inference_main.py 的第23行(可参考第24行注释的格式),以及26行的变调,修改完保存时注意编码应为 UTF-8
4. 在终端中运行 inference_main.py 开始推理,音频将输出至 SUI-svc-3.0\\results\\ 文件夹
```
python inference_main.py
```
""")
app.launch() |