MakeDiffSinger學(xué)習(xí)記錄
2023.8.17學(xué)習(xí)記錄僅供參考
自動(dòng)標(biāo)注部分https://www.bilibili.com/read/cv25820501?spm_id_from=333.9
https://github.com/openvpi/MakeDiffSinger
MakeDiffSinger在colab的CUP模式

#拷貝OPENVPI官方數(shù)據(jù)
%cd /content
!git clone https://github.com/openvpi/MakeDiffSinger.git

#?安裝aria2
!apt -y install -qq aria2

#?下載語(yǔ)音模型重命名mfa.zip放在content/MakeDiffSinger
!aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/datasets/fox7005/tool/resolve/main/mfa-opencpop-extension.zip -d /content/MakeDiffSinger -o mfa.zip

#@title 安裝 conda的colab版本condacolab執(zhí)行后會(huì)自動(dòng)重啟
!pip install -q condacolab
import condacolab
condacolab.install()

#檢查是否安裝成功condacolab上一步自動(dòng)重啟后執(zhí)行
import condacolab
condacolab.check()


#在conda中建立虛擬環(huán)境名mfa,python版本3.8
!conda create -n mfa python=3.8 --yes
#激活虛擬環(huán)境mfa和本地版區(qū)別去掉conda,不去掉不知道怎么解決shell
#!空格activate mfa
! activate mfa? ? ? ??

#安裝mfa2.0.6強(qiáng)制對(duì)齊據(jù)說這個(gè)版本對(duì)中文支持最好
!conda install -c conda-forge montreal-forced-aligner==2.0.6 --yes

#在mfa安裝依賴環(huán)境
%cd /content/MakeDiffSinger/acoustic_forced_alignment
!pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
!pip install ipykernel

#@title 檢查音頻長(zhǎng)度是否正確(如果是整首歌請(qǐng)?zhí)^)
!python validate_lengths.py --dir /content/raw
#如果上一篇標(biāo)注lab和拼音文件還在?/content/raw(替換自己的文件路徑)

#@title 檢查標(biāo)記片段是否正確(如果是整首歌請(qǐng)?zhí)^)
!python validate_labels.py --dir /content/raw?--dictionary dictionaries/opencpop-extension.txt

#@title 重新格式化錄音到新建rawmfa文件夾
%cd /content
!mkdir -p rawmfa
%cd /content/MakeDiffSinger/acoustic_forced_alignment
!python reformat_wavs.py --src /content/raw?--dst /content/rawmfa

#新建textgrids文件夾
%cd /content
!mkdir -p textgrids

#@title 使用 MFA 處理語(yǔ)料庫(kù)
!mfa align /content/rawmfa /content/MakeDiffSinger/acoustic_forced_alignment/dictionaries/opencpop-extension.txt /content/MakeDiffSinger/mfa.zip /content/textgrids --beam 100 --clean --overwrite

#加查是否已經(jīng)生成所有文件,如果是中途掉或者中途添加文件也可以用它測(cè)試是否都生成
%cd /content/MakeDiffSinger/acoustic_forced_alignment
!python check_tg.py --wavs /content/rawmfa --tg /content/textgrids

#@title 改進(jìn)和完成的 TextGrids導(dǎo)入textgrids2文件夾
!mkdir -p /content/textgrids2
!python enhance_tg.py --wavs /content/rawmfa --dictionary /content/MakeDiffSinger/acoustic_forced_alignment/dictionaries/opencpop-extension.txt --src /content/textgrids --dst /content/textgrids2
#如果希望效果更好可以通過Vlabler(https://github.com/sdercolin/vlabeler) 在mfa的基礎(chǔ)上精修你的TextGrids對(duì)齊文件

#@title 創(chuàng)建最終的數(shù)據(jù)集diffsingerdatsaet修改成歌手名
#--dataset這是參數(shù)別動(dòng)
!mkdir -p /content/diffsingerdatsaet
!python build_dataset.py --wavs /content/rawmfa --tg /content/textgrids2 --dataset /content/diffsingerdatsaet

#備份最后的數(shù)據(jù)集到網(wǎng)盤根目錄
#請(qǐng)確保已經(jīng)加載網(wǎng)盤
%cd /content
!zip -r diffsingerdatsaet.zip /content/diffsingerdatsaet
!cp?/content/diffsingerdatsaet.zip /content/drive/MyDrive/

根據(jù)官方字典修改config_acoustic.yaml就可預(yù)處理
文件在configs/templates中,修改后推薦放到數(shù)據(jù)集文件夾方便以后使用
把diffsingerdatsaet.zip解壓到DiffSinger/data/目錄下
如果是gpu模式可繼續(xù)使用,免費(fèi)的時(shí)間有限所以推薦單獨(dú)保存此副本cpu模式使用以后制作其他數(shù)據(jù)集

#@title 自動(dòng)音高訓(xùn)練集制作創(chuàng)建虛擬環(huán)境makediffsinger
!conda create -n makediffsinger python=3.8 --yes
#激活虛擬環(huán)境
! activate makediffsinger
#虛擬環(huán)境MakeDiffSinger安裝依賴
%cd /content/MakeDiffSinger/variance-temp-solution
!pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/
#轉(zhuǎn)換transcriptions.txt為transcriptions.csv如果已經(jīng)有csv跳過繼續(xù)下一步
!python convert_txt.py 你的文件路徑/transcriptions.txt
#二分式詞典(漢語(yǔ)普通話、日語(yǔ)等)
!python add_ph_num.py /content/diffsingerdatsaet/transcriptions.csv --dictionary /content/MakeDiffSinger/acoustic_forced_alignment/dictionaries/opencpop-extension.txt

#單音節(jié)音素系統(tǒng)(粵語(yǔ)、韓語(yǔ)等)vowels.txt consonants.txt需要自己制作沒有跳過
!python add_ph_num.py /content/datsaetge/transcriptions.csv --vowels ?/content/diffsingerdatsaet/vowels.txt --consonants ?/content/diffsingerdatsaet/consonants.txt

#推斷音高值
!python estimate_midi.py /content/diffsingerdatsaet/transcriptions.csv /content/diffsingerdatsaet/wavs
#優(yōu)化 MIDI 序列 沒需要跳過
!python convert_ds.py csv2ds /content/diffsingerdatsaet/transcriptions.csv /content/diffsingerdatsaet/wavs
#這里會(huì)在音頻文件夾內(nèi)生成同名DS文件,之前說的如果你數(shù)據(jù)集里是一個(gè)單文件一整首歌的聲成的ds文件就可以直接用作推理,這只是個(gè)想法,測(cè)試可以使用,也就是在標(biāo)注的時(shí)候4分鐘的音頻是無法識(shí)別漢字,但你只需要去網(wǎng)上找到歌詞漢VTuberTalktools/hanzi_to_pinyin.py轉(zhuǎn)成標(biāo)注lab,或者自己改成拼音標(biāo)注,然后運(yùn)行到這里就可以了得到歌詞、持續(xù)時(shí)間、音高的ds文件,mfa和其他處理都支持4分鐘的長(zhǎng)音頻,根據(jù)官方說的不能完全識(shí)別么好,也推薦了工具修改SlurCutter,https://github.com/openvpi/dataset-tools/releases這工具集合標(biāo)注lab,也可以整首歌詞漢字用這個(gè)轉(zhuǎn)lab標(biāo)注,MinLabel在SlurCutter工具包文件夾內(nèi)

#將.ds文件重新組合為transcriptions.csv如果沒修改跳過,
!python convert_ds.py ds2csv /content/diffsingerdatsaet/wavs /content/datsaetge/transcriptions.csv

這里就完成了音高模型數(shù)據(jù)集前期準(zhǔn)備,之前備份了只需要備份transcriptions.csv
config.variance.yaml修改后預(yù)處理
這里是DiffSinger2.0.0僅供參考
根據(jù)官方openvpi維護(hù)版教程使用
https://github.com/openvpi/DiffSinger
文本教程地址
https://openvpi-docs.feishu.cn/wiki/KmBFwoYDEixrS4kHcTAcajPinPe