Spaces:
Runtime error
Runtime error
feat: update new choice for sts
Browse files- app.py +25 -14
- inference_main.py +59 -0
- local.md +36 -0
- requirements.txt +2 -1
app.py
CHANGED
|
@@ -4,18 +4,21 @@ import gradio as gr
|
|
| 4 |
import librosa
|
| 5 |
import numpy as np
|
| 6 |
import soundfile
|
| 7 |
-
import torch
|
| 8 |
from inference.infer_tool import Svc
|
| 9 |
import logging
|
|
|
|
| 10 |
|
| 11 |
logging.getLogger('numba').setLevel(logging.WARNING)
|
| 12 |
|
| 13 |
-
|
|
|
|
| 14 |
config_name = "configs/config.json"
|
| 15 |
|
| 16 |
-
|
|
|
|
| 17 |
sid_map = {
|
| 18 |
-
"
|
|
|
|
| 19 |
}
|
| 20 |
|
| 21 |
|
|
@@ -25,20 +28,25 @@ def vc_fn(sid, input_audio, vc_transform):
|
|
| 25 |
sampling_rate, audio = input_audio
|
| 26 |
# print(audio.shape,sampling_rate)
|
| 27 |
duration = audio.shape[0] / sampling_rate
|
| 28 |
-
if duration >
|
| 29 |
-
return "请上传小于
|
| 30 |
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
| 31 |
if len(audio.shape) > 1:
|
| 32 |
audio = librosa.to_mono(audio.transpose(1, 0))
|
| 33 |
if sampling_rate != 32000:
|
| 34 |
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=32000)
|
|
|
|
| 35 |
print(audio.shape)
|
| 36 |
out_wav_path = io.BytesIO()
|
| 37 |
soundfile.write(out_wav_path, audio, 32000, format="wav")
|
| 38 |
out_wav_path.seek(0)
|
| 39 |
|
| 40 |
-
sid =
|
| 41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
_audio = out_audio.cpu().numpy()
|
| 43 |
return "Success", (32000, _audio)
|
| 44 |
|
|
@@ -60,8 +68,11 @@ with app:
|
|
| 60 |
|
| 61 |
# start!
|
| 62 |
上传一段干音(45s以内),然后点击提交即可开始推理!
|
|
|
|
|
|
|
| 63 |
""")
|
| 64 |
-
sid = gr.Dropdown(label="音色", choices=[
|
|
|
|
| 65 |
vc_input3 = gr.Audio(label="上传音频(长度小于45秒)")
|
| 66 |
vc_transform = gr.Number(
|
| 67 |
label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0)
|
|
@@ -70,13 +81,13 @@ with app:
|
|
| 70 |
vc_output2 = gr.Audio(label="Output Audio")
|
| 71 |
gr.Markdown(value="""
|
| 72 |
## 注意
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
如果要在本地使用该demo,请使用 `git lfs clone` 该仓库,安装requirements.txt后命令行运行`python ./app.py`即可
|
| 76 |
|
| 77 |
-
如果
|
| 78 |
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
""")
|
| 81 |
vc_submit.click(vc_fn, [sid, vc_input3, vc_transform], [
|
| 82 |
vc_output1, vc_output2])
|
|
|
|
| 4 |
import librosa
|
| 5 |
import numpy as np
|
| 6 |
import soundfile
|
|
|
|
| 7 |
from inference.infer_tool import Svc
|
| 8 |
import logging
|
| 9 |
+
from logmmse import logmmse
|
| 10 |
|
| 11 |
logging.getLogger('numba').setLevel(logging.WARNING)
|
| 12 |
|
| 13 |
+
model_sing = "logs/32k/sing1.pth"
|
| 14 |
+
model_talk = "logs/32k/talk1.pth"
|
| 15 |
config_name = "configs/config.json"
|
| 16 |
|
| 17 |
+
svc_sing = Svc(model_sing, config_name)
|
| 18 |
+
svc_talk = Svc(model_talk, config_name)
|
| 19 |
sid_map = {
|
| 20 |
+
"唱歌": "yukie",
|
| 21 |
+
"杂谈": "yukie"
|
| 22 |
}
|
| 23 |
|
| 24 |
|
|
|
|
| 28 |
sampling_rate, audio = input_audio
|
| 29 |
# print(audio.shape,sampling_rate)
|
| 30 |
duration = audio.shape[0] / sampling_rate
|
| 31 |
+
if duration > 60:
|
| 32 |
+
return "请上传小于60s的音频,需要转换长音频请本地进行转换", None
|
| 33 |
audio = (audio / np.iinfo(audio.dtype).max).astype(np.float32)
|
| 34 |
if len(audio.shape) > 1:
|
| 35 |
audio = librosa.to_mono(audio.transpose(1, 0))
|
| 36 |
if sampling_rate != 32000:
|
| 37 |
audio = librosa.resample(audio, orig_sr=sampling_rate, target_sr=32000)
|
| 38 |
+
audio = logmmse(audio, 32000)
|
| 39 |
print(audio.shape)
|
| 40 |
out_wav_path = io.BytesIO()
|
| 41 |
soundfile.write(out_wav_path, audio, 32000, format="wav")
|
| 42 |
out_wav_path.seek(0)
|
| 43 |
|
| 44 |
+
if sid == "唱歌":
|
| 45 |
+
out_audio, _out_sr = svc_sing.infer(
|
| 46 |
+
"yukie", vc_transform, out_wav_path)
|
| 47 |
+
else:
|
| 48 |
+
out_audio, _out_sr = svc_talk.infer(
|
| 49 |
+
"yukie", vc_transform, out_wav_path)
|
| 50 |
_audio = out_audio.cpu().numpy()
|
| 51 |
return "Success", (32000, _audio)
|
| 52 |
|
|
|
|
| 68 |
|
| 69 |
# start!
|
| 70 |
上传一段干音(45s以内),然后点击提交即可开始推理!
|
| 71 |
+
|
| 72 |
+
请使用无bgm,纯人声的音频来进行测试,且本模型无法识别出带有和声的部分,使用较高品质干净的纯人声会有更好的体验
|
| 73 |
""")
|
| 74 |
+
sid = gr.Dropdown(label="音色", choices=[
|
| 75 |
+
"唱歌", "杂谈"], value="唱歌")
|
| 76 |
vc_input3 = gr.Audio(label="上传音频(长度小于45秒)")
|
| 77 |
vc_transform = gr.Number(
|
| 78 |
label="变调(整数,可以正负,半音数量,升高八度就是12)", value=0)
|
|
|
|
| 81 |
vc_output2 = gr.Audio(label="Output Audio")
|
| 82 |
gr.Markdown(value="""
|
| 83 |
## 注意
|
| 84 |
+
在线版只简单的使用logmmse进行降噪处理,与本地处理的方式有所不同,同时限制了最大处理时间为45s
|
|
|
|
|
|
|
| 85 |
|
| 86 |
+
如果要在本地使用该demo,请使用 `git lfs clone https://huggingface.co/spaces/yukie/yukie-sovits3`克隆该仓库([简单教程](https://huggingface.co/spaces/yukie/yukie-sovits3/edit/main/local.md))
|
| 87 |
|
| 88 |
+
# todo:
|
| 89 |
+
1. 降噪算法优化
|
| 90 |
+
2. 内部逻辑优化,使得在线平台性能较差情况下支持60s以上的片段,同时减少计算时间
|
| 91 |
""")
|
| 92 |
vc_submit.click(vc_fn, [sid, vc_input3, vc_transform], [
|
| 93 |
vc_output1, vc_output2])
|
inference_main.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import logging
|
| 3 |
+
import time
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
import librosa
|
| 7 |
+
import numpy as np
|
| 8 |
+
import soundfile
|
| 9 |
+
|
| 10 |
+
from inference import infer_tool
|
| 11 |
+
from inference import slicer
|
| 12 |
+
from inference.infer_tool import Svc
|
| 13 |
+
|
| 14 |
+
logging.getLogger('numba').setLevel(logging.WARNING)
|
| 15 |
+
chunks_dict = infer_tool.read_temp("inference/chunks_temp.json")
|
| 16 |
+
|
| 17 |
+
model_path = "logs/32k/sing1.pth"
|
| 18 |
+
config_path = "configs/config.json"
|
| 19 |
+
svc_model = Svc(model_path, config_path)
|
| 20 |
+
infer_tool.mkdir(["raw", "results"])
|
| 21 |
+
|
| 22 |
+
# 支持多个wav文件,放在raw文件夹下,并修改clean_names为对应文件名(不需要文件后缀)
|
| 23 |
+
clean_names = ["cccc1"]
|
| 24 |
+
trans = [0] # 音高调整,支持正负(半音)
|
| 25 |
+
spk_list = ['yukie'] # 每次同时合成多语者音色
|
| 26 |
+
slice_db = -40 # 默认-40,嘈杂的音频可以-30,干声保留呼吸可以-50
|
| 27 |
+
wav_format = 'flac' # 音频输出格式
|
| 28 |
+
|
| 29 |
+
infer_tool.fill_a_to_b(trans, clean_names)
|
| 30 |
+
for clean_name, tran in zip(clean_names, trans):
|
| 31 |
+
raw_audio_path = f"raw/{clean_name}"
|
| 32 |
+
if "." not in raw_audio_path:
|
| 33 |
+
raw_audio_path += ".wav"
|
| 34 |
+
infer_tool.format_wav(raw_audio_path)
|
| 35 |
+
wav_path = Path(raw_audio_path).with_suffix('.wav')
|
| 36 |
+
chunks = slicer.cut(wav_path, db_thresh=slice_db)
|
| 37 |
+
audio_data, audio_sr = slicer.chunks2audio(wav_path, chunks)
|
| 38 |
+
|
| 39 |
+
for spk in spk_list:
|
| 40 |
+
audio = []
|
| 41 |
+
for (slice_tag, data) in audio_data:
|
| 42 |
+
print(
|
| 43 |
+
f'#=====segment start, {round(len(data) / audio_sr, 3)}s======')
|
| 44 |
+
length = int(
|
| 45 |
+
np.ceil(len(data) / audio_sr * svc_model.target_sample))
|
| 46 |
+
raw_path = io.BytesIO()
|
| 47 |
+
soundfile.write(raw_path, data, audio_sr, format="wav")
|
| 48 |
+
raw_path.seek(0)
|
| 49 |
+
if slice_tag:
|
| 50 |
+
print('jump empty segment')
|
| 51 |
+
_audio = np.zeros(length)
|
| 52 |
+
else:
|
| 53 |
+
out_audio, out_sr = svc_model.infer(spk, tran, raw_path)
|
| 54 |
+
_audio = out_audio.cpu().numpy()
|
| 55 |
+
audio.extend(list(_audio))
|
| 56 |
+
|
| 57 |
+
res_path = f'./results/{clean_name}_{tran}key_{spk}-6-1.{wav_format}'
|
| 58 |
+
soundfile.write(res_path, audio,
|
| 59 |
+
svc_model.target_sample, format=wav_format)
|
local.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 前言
|
| 2 |
+
本教程用于简单的本地推理使用,适合全新环境下使用
|
| 3 |
+
|
| 4 |
+
# START!
|
| 5 |
+
## step0
|
| 6 |
+
先行安装python环境`https://www.python.org/ftp/python/3.9.9/python-3.9.9-amd64.exe`,下载后安装,全部都默认即可
|
| 7 |
+
这里版本也可以自行选择,但是尽量不要选择3.10及以上版本,又可能有部分依赖高版本有问题
|
| 8 |
+
|
| 9 |
+
## step1
|
| 10 |
+
`win + r`后输入`powershell`进入终端,当然是win11系统下输入`wt`会有更好体验
|
| 11 |
+
|
| 12 |
+
然后使用`git clone https://huggingface.co/spaces/yukie/yukie-talk`克隆该项目到本地,如果提示找不到git,需要自行下载安装git
|
| 13 |
+
|
| 14 |
+
下载完成后,使用`cd <项目地址>`进入项目文件夹(eg. "cd ./yukie-talk")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
## step2
|
| 20 |
+
输入`pip install -r requirements.txt`安装对应依赖,没有梯子的话速度会比较慢,可以自行百度搜索python换源,这里不做演示
|
| 21 |
+
|
| 22 |
+
这一步可能会出现较多问题,但都是各自计算机系统环境不同,难以直接列出,需要各自自行查找解决方案
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
## step3
|
| 27 |
+
理论上完成上一步后,wt中使用cd命令进入该项目解压后的文件夹(eg. "cd D:\Coding\yukie-sovits"),就可以`python ./app.py`直接运行了
|
| 28 |
+
|
| 29 |
+
需要进阶处理时,则使用`python ./inference_main.py`,这里需要一定的编程基础更佳,需要自行修改inference_main.py中参数(clean_names等)
|
| 30 |
+
|
| 31 |
+
但是由于本地环境的不同,会出现各自不同的问题,这里列出其中一部分
|
| 32 |
+
|
| 33 |
+
1. 输入文件为mp3等无法进行推理:
|
| 34 |
+
这是由于默认只支持wav格式,而使用mp3等需要电脑环境中有ffmpeg,需要下载ffempg(https://www.gyan.dev/ffmpeg/builds/packages/ffmpeg-5.1.2-full_build.7z),然后解压出后将其中bin文件夹加入系统path中
|
| 35 |
+
|
| 36 |
+
1. 其他
|
requirements.txt
CHANGED
|
@@ -13,4 +13,5 @@ tqdm
|
|
| 13 |
scikit-maad
|
| 14 |
praat-parselmouth
|
| 15 |
librosa
|
| 16 |
-
torchvision
|
|
|
|
|
|
| 13 |
scikit-maad
|
| 14 |
praat-parselmouth
|
| 15 |
librosa
|
| 16 |
+
torchvision
|
| 17 |
+
logmmse
|