vits語音合成(基于原版vits)-失敗原因整理
這個教程失敗于nccl(windows無法配置),所以沒成功就不面向需要學習的人了,這篇屬于記錄一下原因和一些配置方式防止自己遺忘的文檔,如果系統(tǒng)是windows就別跟著配前置了,找別的版本吧,(沒有配置使用過)以下是推薦:
https://github.com/PlayVoice/vits_chinese
https://github.com/Plachtaa/VITS-fast-fine-tuning
https://github.com/svc-develop-team/so-vits-svc
https://github.com/Edresson/YourTTS/
本文檔基于:
windows11
CUDA 12.1
Anaconda
Anaconda對于配置單個AI可有可無,這是用來用于虛擬多個python環(huán)境,防止之后組合別的ai出現(xiàn)環(huán)境和包不匹配導致安裝多AI失敗的情況,比如擬聲鳥需要的是python3.9,而stablediffusion需要的是python3.10,以及各個包之間會有相同的依賴庫但版本不同
NCCL(無法在windows運行)
顯卡2080ti
開始:
查看當前電腦的CUDA版本:
打開“命令提示符(CMD)”
輸入nvidia-smi

下載所用文件:
下載vits項目(Github)
https://github.com/jaywalnut310/vits
下載AnaConda(Windows):
https://www.anaconda.com (主頁)
https://repo.anaconda.com/archive/Anaconda3-2023.03-Windows-x86_64.exe
https://mirrors.bfsu.edu.cn/anaconda/(北京外國語大學開源軟件鏡像站)
msvc:
https://visualstudio.microsoft.com/zh-hans/downloads/
下載pytorch文件(以防各種莫名其妙的pytorch報錯):
命令行方式:https://pytorch.org/get-started/locally/
Pytorch下載:
https://download.pytorch.org/whl/ (所有庫下載)
pytorch:
https://download.pytorch.org/whl/torch
cp:python版本(cp310=python3.10版本)
cu:cuda版本(cu118=cuda11.8版本)? ? ?使用顯卡
cu118可以適用于cuda12.1版本
cpu:cpu版本? ? 使用CPU
cpu版本適用于顯卡顯存不足6g的電腦
2.0.0為最新版本
Pytorch Audio
https://download.pytorch.org/whl/torchaudio
Pytorch Vision
https://download.pytorch.org/torchvision/
CUDA下載(CUDA Toolkit):
https://developer.nvidia.com/cuda-downloads?
需要的軟件:
buzz(語音轉文字,基于openai的whisper)
https://github.com/chidiwilliams/buzz/releases/tag/v0.7.2
audio-slicer(視頻切片,可以多切幾次弄多一點訓練材料)
https://github.com/flutydeer/audio-slicer/releases/tag/v1.1.0
Espeak:
https://github.com/espeak-ng/espeak-ng/releases/tag/1.51
FFmpeg:
https://github.com/BtbN/FFmpeg-Builds/releases(win,大小126M的版本)
環(huán)境變量


nvcc,ffmpeg,git,anaconda等軟件的命令也需要配置環(huán)境變量
假設我的項目路徑在
C:\Users\用戶名\Desktop\AIS\vits-main\
Vits配置安裝:
首先conda create -n vits python=3.9 創(chuàng)建一個3.9的python環(huán)境
conda activate vits
cd?C:\Users\用戶名\Desktop\AIS\vits-main\
pip install 下好的torch,torchaudio,torchvision文件路徑
requirement.txt文件內容修改為:
Cython==0.29.21
librosa==0.8.0
matplotlib==3.3.1
numpy==1.18.5
phonemizer==2.2.1
scipy>=1.5.2
tensorboard==2.3.0
Unidecode==1.1.1
pip install -r requirement.txt
修改項目文件:
訓練材料(煉丹材料):
基于https://www.bilibili.com/read/cv21153903/
修改內容基于https://github.com/wac81/vits_chinese/tree/37edf5f4c5a1b1f746729bdb5c16bfb3b0bd52e4
text文件夾中cleaners.py:

def chinese_cleaners1(text):from pypinyin import Style, pinyinphones = [phone[0] for phone in pinyin(text, style=Style.TONE3)]return ' '.join(phones)def chinese_cleaners2(text):phones = [pfor phone in pinyin(text, style=Style.TONE3)for p in [get_initials(phone[0], strict=True),get_finals(phone[0][:-1], strict=True) + phone[0][-1]if phone[0][-1].isdigit()else get_finals(phone[0], strict=True)if phone[0][-1].isalnum()else phone[0],]# Remove the case of individual tones as a phonemeif len(p) != 0 and not p.isdigit()]return phones
text中symbols.py改的一樣:

""" from https://github.com/keithito/tacotron """'''Defines the set of symbols used in text input to the model.'''_pad ? ? ? ?= '_'_punctuation = ';:,.!???—…"??“” '_punctuation_zh = ';:,。!?-“”《》、 '_letters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'_numbers = '123450'_others = ''_letters_ipa = "ɑ?????β?????e??????????ɡ??????????????????????????θ??????????????????????χ??????????∥???????????????↓↑→↗↘'?'?"# Export all symbols:symbols = [_pad] + list(_punctuation) + list(_letters) + list(_letters_ipa)symbols_zh = [_pad] + list(_punctuation_zh) + ?list(_letters) + list(_numbers)# Special symbol idsSPACE_ID = symbols.index(" ")
preprocess文件:

parser.add_argument("--text_cleaners", nargs="+", default=["chinese_cleaners1"]) ? # english_cleaners2
煉丹材料和list.txt放置方式以及config配置,默認基于教程:
https://www.bilibili.com/read/cv21153903/
以下操作全在
C:\Users\用戶名\Desktop\AIS\vits-main\文件夾下
config下創(chuàng)建文件(基于ljs_base),文件名自定義:
config.json
在這里我們選擇給出的chinese_base.json為例。
train部分:
eval_interval為保存間隔,默認的1000即可以滿足保存的需求,設置過小會訓練過程會耗費大量時間在保存上;設置過大如果訓練出現(xiàn)問題無法滿足及時保存最近的模型的需求。
epochs迭代次數(shù),一般來說比較好的數(shù)據(jù)集質量不到一千就能出現(xiàn)效果,兩千往上勉強可以使用,這里個人建議一萬到兩萬效果最佳。
batch_size一定要改!請按照你的顯存酌情修改(否則開始訓練就爆顯存),6G大概為4左右,10G可以到6左右。
fp16_run半精度訓練,一般按照默認開啟即可,如果你對你的配置過于自信可以嘗試關閉。
data部分:
前兩行要改成我們前面保存list.txt和list_val.txt路徑,即filelists/list.txt.cleaned和filelists/list_val.txt.cleaned
cleaned是preprocess(預處理)后的文件
n_speakers說話人數(shù),單人改為0
回到anaconda prompt:

按照官方給的方式使用
cd monotonic_align?
python setup.py build_ext --inplace
小坑:
monotonic_align下還要建立一個文件夾叫monotonic_align,不然報錯
python preprocess.py --text_index 1 --filelists 兩個list.txt文件的位置,中間用空格分開
(windows無法運行的最后一步)
python?train.py -c 自定義config.json文件路徑?-m 輸出后的model名稱
# LJ Speech
python train.py -c configs/ljs_base.json -m ljs_base
# VCTK
python train_ms.py -c configs/vctk_base.json -m vctk_base
問題總覽:
No module named 'numpy.random.bit_generator'
pip install numpy==1.19.3
TypeError: Descriptors cannot not be created directly. If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0. If you cannot immediately regenerate your protos, some other possible workarounds are: 1. Downgrade the protobuf package to 3.20.x or lower. 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).
pip install protobuf==3.20.0
ValueError: port must have value from 0 to 65535 but was 80000.
train.py|train_ms.py
? os.environ['MASTER_PORT'] = '80000'
改為沒被占用的端口號(80,3306,22,21,20,443等常用端口不要去設置,比如:網(wǎng)頁常用端口,后端和數(shù)據(jù)庫常用端口,應用服務已占用端口如微信、MC服務器等,服務占用的端口,數(shù)據(jù)庫常用端口,文件傳輸常用端口,各種協(xié)議如郵件傳輸協(xié)議的常用端口等端口,一定需要避免設置這些端口,且范圍控制在0~65535中)
例子:os.environ['MASTER_PORT'] =?'5321'
windows無法配置的原因:
RuntimeError("Distributed package doesn't have NCCL " "built in")
RuntimeError: Distributed package doesn't have NCCL built in
NVIDIA Collective Communications Library (NCCL) | NVIDIA Developer
https://developer.nvidia.com/nccl
https://docs.nvidia.com/deeplearning/nccl/install-guide/index.html
坑踩爛了都,這個nccl官方版本不適用windows,沒裝雙系統(tǒng)沒法繼續(xù),文檔結束