|
3 years ago | |
---|---|---|
.. | ||
local | 3 years ago | |
README.md | 3 years ago | |
path.sh | 3 years ago | |
run.sh | 3 years ago |
README.md
Tacotron2 + AISHELL-3 Voice Cloning
This example contains code used to train a Tacotron2 model with AISHELL-3. The trained model can be used in Voice Cloning Task, We refer to the model structure of Transfer Learning from Speaker Verification to Multispeaker Text-To-Speech Synthesis. The general steps are as follows:
- Speaker Encoder: We use Speaker Verification to train a speaker encoder. Datasets used in this task are different from those used in Tacotron2 because the transcriptions are not needed, we use more datasets, refer to ge2e.
- Synthesizer: We use the trained speaker encoder to generate speaker embedding for each sentence in AISHELL-3. This embedding is an extra input of Tacotron2 which will be concated with encoder outputs.
- Vocoder: We use WaveFlow as the neural Vocoder, refer to waveflow.
Get Started
Assume the path to the dataset is ~/datasets/data_aishell3
.
Assume the path to the MFA result of AISHELL-3 is ./alignment
.
Assume the path to the pretrained ge2e model is ge2e_ckpt_path=./ge2e_ckpt_0.3/step-3000000
Run the command below to
- source path.
- preprocess the dataset.
- train the model.
- start a voice cloning inference.
./run.sh
You can choose a range of stages you want to run, or set stage
equal to stop-stage
to use only one stage, for example, run the following command will only preprocess the dataset.
./run.sh --stage 0 --stop-stage 0
Data Preprocessing
CUDA_VISIBLE_DEVICES=${gpus} ./local/preprocess.sh ${input} ${preprocess_path} ${alignment} ${ge2e_ckpt_path}
Generate Speaker Embedding
Use pretrained GE2E (speaker encoder) to generate speaker embedding for each sentence in AISHELL-3, which has the same file structure with wav files and the format is .npy
.
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
python3 ${BIN_DIR}/../ge2e/inference.py \
--input=${input} \
--output=${preprocess_path}/embed \
--ngpu=1 \
--checkpoint_path=${ge2e_ckpt_path}
fi
The computing time of utterance embedding can be x hours.
Process Wav
There is silence in the edge of AISHELL-3's wavs, and the audio amplitude is very small, so, we need to remove the silence and normalize the audio. You can the silence remove method based on volume or energy, but the effect is not very good, We use MFA to get the alignment of text and speech, then utilize the alignment results to remove the silence.
We use Montreal Force Aligner 1.0. The label in aishell3 includes pinyin,so the lexicon we provided to MFA is pinyin rather than Chinese characters. And the prosody marks($
and %
) need to be removed. You should preprocess the dataset into the format which MFA needs, the texts have the same name with wavs and have the suffix .lab
.
We use lexicon.txt as the lexicon.
You can download the alignment results from here alignment_aishell3.tar.gz, or train your MFA model reference to mfa example (use MFA1.x now) of our repo.
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
echo "Process wav ..."
python3 ${BIN_DIR}/process_wav.py \
--input=${input}/wav \
--output=${preprocess_path}/normalized_wav \
--alignment=${alignment}
fi
Preprocess Transcription
We revert the transcription into phones
and tones
. It is worth noting that our processing here is different from that used for MFA, we separated the tones. This is a processing method, of course, you can only segment initials and vowels.
if [ ${stage} -le 2 ] && [ ${stop_stage} -ge 2 ]; then
python3 ${BIN_DIR}/preprocess_transcription.py \
--input=${input} \
--output=${preprocess_path}
fi
The default input is ~/datasets/data_aishell3/train
,which contains label_train-set.txt
, the processed results are metadata.yaml
and metadata.pickle
. the former is a text format for easy viewing, and the latter is a binary format for direct reading.
Extract Mel
if [ ${stage} -le 3 ] && [ ${stop_stage} -ge 3 ]; then
python3 ${BIN_DIR}/extract_mel.py \
--input=${preprocess_path}/normalized_wav \
--output=${preprocess_path}/mel
fi
Model Training
CUDA_VISIBLE_DEVICES=${gpus} ./local/train.sh ${preprocess_path} ${train_output_path}
Our model removes stop token prediction in Tacotron2, because of the problem of the extremely unbalanced proportion of positive and negative samples of stop token prediction, and it's very sensitive to the clip of audio silence. We use the last symbol from the highest point of attention to the encoder side as the termination condition.
In addition, to accelerate the convergence of the model, we add guided attention loss
to induce the alignment between encoder and decoder to show diagonal lines faster.
Voice Cloning
CUDA_VISIBLE_DEVICES=${gpus} ./local/voice_cloning.sh ${ge2e_params_path} ${tacotron2_params_path} ${waveflow_params_path} ${vc_input} ${vc_output}