so-vits-svc 4.1 声音克隆 项目实现

  1. 介绍
  2. 准备工作
    1. 环境安装
    2. 环境安装问题
    3. 音频准备
    4. 数据预处理
  3. 训练

重要声明


不要滥用技术,做一个遵纪守法好公民!!!

任何涉及真人的东西都与开发者的意图背道而驰。请自行解决数据集授权问题,禁止使用非授权数据集进行训练!任何由于使用非授权数据集进行训练造成的问题,需自行承担全部责任和后果!

1. 介绍


项目链接:https://github.com/MaxMax2016/so-vits-svc

1.1 兼容4.0模型的问题

  • 可通过修改 4.0 模型的 config.json 对 4.0 的模型进行支持,需要在 config.json 的 model 字段中添加 speech_encoder 字段,具体见下
  "model": {
    .........
    "ssl_dim": 256,
    "n_speakers": 200,
    "speech_encoder":"vec256l9"
  }

2. 准备工作


  • 环境安装
  • 预训练模型下载
  • 数据准备
  • 数据预处理

2.1 环境安装

  • 官网建议 Python版本 3.8.9(我这边直接Python=3.8,也能运行)

win+R输入cmd,打开控制终端,创建名为svc的虚拟环境,激活虚拟环境:

conda create -n svc python=3.8
activate svc
  • 安装环境之前先安装C++组件,否则会提示C++ extension is not available. 下载地址:https://visualstudio.microsoft.com/zh-hans/visual-cpp-build-tools/

  • 进入到项目根目录安装依赖:
    • 通过cd命令逐一进入
    • 直接来到主文件在导航栏中输入cmd

通过下方命令安装依赖(要在虚拟环境下):

pip install -r requirements.txt

2.2 安装环境可能出现的报错:

ERROR:Could not find a version that satisfies the requirment selenium (from version: none)
ERROR: No matching distribution found for selenium

原因一:

pip的版本过低,需要升级一下,可以执行以下命令进行尝试

解决方法:

 python -m pip install --upgrade pip

原因二:

当前库不行,切换库。(详情见文章:Python中pip切换国内源)

解决方法(这里提供临时使用):

pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple

2.3 预训练模型下载

  • 编码器(必须)
  • 预训练底模,扩散模型底模(可选)
  • NSF-HIFIGAN 模型(可选,使用扩散模型时必须下载)
  • RMVPE(可选)

编码器
推荐使用 contentvec 作为声音编码器(更多编码器见github)

或者下载下面的 ContentVec,大小只有 199MB,但效果相同:

  • contentvec :hubert_base.pt
    • 将文件名改为checkpoint_best_legacy_500.pt后,放在pretrain目录下

预训练底模文件

下载路径:G_0.pth D_0.pth

  • 放在logs/44k目录下
  • 扩散模型预训练底模文件: model_0.pt

    • 放在logs/44k/diffusion目录下

!!!底模的使用一般不会引起版权问题,但是还是要注意一下,如 事先询问作者。

NSF-HIFIGAN(想要使用扩散模型时,需要使用)

如果使用NSF-HIFIGAN 增强器浅层扩散的话,需要下载预训练的 NSF-HIFIGAN 模型,如果不需要可以不下载

  • 预训练的 NSF-HIFIGAN 声码器 :nsf_hifigan_20221211.zip
    • 解压后,将四个文件放在pretrain/nsf_hifigan目录下

RMVPE

如果使用rmvpeF0预测器的话,需要下载预训练的 RMVPE 模型

  • 下载模型rmvpe.zip,目前首推该权重。

    • 解压缩rmvpe.zip,并将其中的model.pt文件改名为rmvpe.pt并放在pretrain目录下

数据集准备


说话人1和说话人2的清晰音频各1小时

将音频切割为5-15秒的短音频,稍微长点也无所谓(文件类型必须 wav格式)

文件存放结构:

dataset_raw
├───speaker0
│   ├───xxx1-xxx1.wav
│   ├───...
│   └───Lxx-0xx8.wav
└───speaker1
    ├───xx2-0xxx2.wav
    ├───...
    └───xxx7-xxx007.wav

数据预处理


  •  重采样至 44100Hz 单声道

python resample.py

  • 自动划分训练集、验证集,以及自动生成配置文件

python preprocess_flist_config.py --speech_encoder vec768l12

 

  • 使用响度嵌入

       若使用响度嵌入,需要增加--vol_aug参数,比如:

python preprocess_flist_config.py --speech_encoder vec768l12 --vol_aug

 

  • 生成 hubert 与 f0

python preprocess_hubert_f0.py --f0_predictor dio

 

  • 尚若需要浅扩散功能(可选),需要增加--use_diff 参数,比如

python preprocess_hubert_f0.py --f0_predictor dio --use_diff

 

  • 加速预处理(将所有workers分配到多个线程上)

python preprocess_hubert_f0.py --f0_predictor dio --use_diff --num_processes 8

 

模型训练


主模型训练

python train.py -c configs/config.json -m 44k

 训练完成后模型储存在...\logs\44k中。

扩散模型(可选)

python train_diff.py -c configs/diffusion.yaml

模型训练结束后,模型文件保存在logs/44k目录下,扩散模型在logs/44k/diffusion

 

推理


运行webUI.py,自动跳转到网页。

 

  • 模型中传入训练好的主模型(...\logs\44k\G_9600.pth)

  • 配置文件中传入config.json文件(...\configs\config.json)

  • 扩散模型中传入训练好的扩散模型(...\log\44k\diffusion\model_10000.pt)

  • 扩散模型配置文件中传入diffusion.yaml文件(...\config\diffusion.yaml)

  • 选择音色(说话人)

  • 传入音频点击预测

 

常见错误


  • 错误1:
image = image.resize((scaled_width, scaled_height), Image.ANTIALIAS)
AttributeError: module 'PIL.Image' has no attribute 'ANTIALIAS'

原因:Pillow版本过高

解决方法:

pip install Pillow==9.5.0

  • 错误2:
AttributeError("'Dropdown' object has no attribute 'update'")

原因:依赖的版本问题

凡是涉及到 fastapi, gradio, pydantic 这三个依赖的报错

解决方法如下: 请限制以下依赖版本

fastapi==0.84.0 (>0.80.0 <=0.88.0) gradio==3.41.2 (>=3.41.2 <=3.42.0) 
pydantic==1.10.12

总结


优点:

  • 效果理想

  • 实现简便

缺点:

  • 训练时间过长(平均一个epoch需要花费1分钟)。

    • 理论上需要训练10000个epoch。尝试发现1000个epoch效果也还不错。

  • 模型的预测效果极大程度上取决于数据集的数据质量。

  • 音频克隆只能是训练集中的说话人声音互相克隆。

    • 并不能在未训练的情况下,将其他任意音频转换为指定人物的音色。(也可能是训练epoch太少了或者数据集质量不够高,导致模型泛化性不够好)

### So-VITS-SVC 4.1 Project Overview So-VITS-SVC is an advanced voice conversion system that supports multi-speaker singing voice synthesis with real-time performance capabilities[^1]. The version 4.1 of this project has been optimized to provide better quality and efficiency in the conversion process. #### Key Features The key features include support for multiple speakers, improved vocoder stability, enhanced model training speed, and a user-friendly interface designed specifically for both developers and end-users[^2]. ```python import torch from so_vits_svc_41 import inference as vc model_path = "path_to_model.pth" config_path = "path_to_config.json" vc.load_model(model_path, config_path) audio_output = vc.inference(input_audio="input.wav", speaker_id=0) ``` This code snippet demonstrates how one can load a pre-trained model and perform inference using the `so_vits_svc_41` library[^3]. #### Installation Guide For installation, ensure Python 3.7 or higher is installed on your machine along with PyTorch. Detailed instructions are available within the official GitHub repository's README file which includes setting up dependencies such as CUDA if GPU acceleration is desired[^4]. #### Usage Instructions To use So-VITS-SVC 4.1 effectively: - Prepare audio files in WAV format. - Select appropriate parameters like sampling rate according to the provided configuration JSON file. - Utilize command-line tools or integrate into applications via API calls depending upon specific requirements[^5]. --related questions-- 1. What improvements does So-VITS-SVC 4.1 offer over previous versions? 2. How do I train my own dataset using So-VITS-SVC 4.1? 3. Can So-VITS-SVC 4.1 be used commercially without any licensing issues? 4. Are there tutorials available for integrating So-VITS-SVC 4.1 into web services?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值