[TTS]Cantonese FastSpeech2 e2e infer, test=tts (#2927)
parent
004a4d6096
commit
1af9bd47d9
@ -0,0 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
config_path=$1
|
||||
train_output_path=$2
|
||||
ckpt_name=$3
|
||||
|
||||
stage=0
|
||||
stop_stage=0
|
||||
|
||||
# pwgan
|
||||
if [ ${stage} -le 0 ] && [ ${stop_stage} -ge 0 ]; then
|
||||
FLAGS_allocator_strategy=naive_best_fit \
|
||||
FLAGS_fraction_of_gpu_memory_to_use=0.01 \
|
||||
python3 ${BIN_DIR}/../synthesize_e2e.py \
|
||||
--am=fastspeech2_canton \
|
||||
--am_config=${config_path} \
|
||||
--am_ckpt=${train_output_path}/checkpoints/${ckpt_name} \
|
||||
--am_stat=dump/train/speech_stats.npy \
|
||||
--voc=pwgan_aishell3 \
|
||||
--voc_config=pwg_aishell3_ckpt_0.5/default.yaml \
|
||||
--voc_ckpt=pwg_aishell3_ckpt_0.5/snapshot_iter_1000000.pdz \
|
||||
--voc_stat=pwg_aishell3_ckpt_0.5/feats_stats.npy \
|
||||
--lang=canton \
|
||||
--text=${BIN_DIR}/../sentences_canton.txt \
|
||||
--output_dir=${train_output_path}/test_e2e \
|
||||
--phones_dict=dump/phone_id_map.txt \
|
||||
--speaker_dict=dump/speaker_id_map.txt \
|
||||
--spk_id=0 \
|
||||
--inference_dir=${train_output_path}/inference
|
||||
fi
|
||||
|
||||
# hifigan
|
||||
if [ ${stage} -le 1 ] && [ ${stop_stage} -ge 1 ]; then
|
||||
echo "in hifigan syn_e2e"
|
||||
FLAGS_allocator_strategy=naive_best_fit \
|
||||
FLAGS_fraction_of_gpu_memory_to_use=0.01 \
|
||||
python3 ${BIN_DIR}/../synthesize_e2e.py \
|
||||
--am=fastspeech2_canton \
|
||||
--am_config=${config_path} \
|
||||
--am_ckpt=${train_output_path}/checkpoints/${ckpt_name} \
|
||||
--am_stat=dump/train/speech_stats.npy \
|
||||
--voc=hifigan_aishell3 \
|
||||
--voc_config=hifigan_aishell3_ckpt_0.2.0/default.yaml \
|
||||
--voc_ckpt=hifigan_aishell3_ckpt_0.2.0/snapshot_iter_2500000.pdz \
|
||||
--voc_stat=hifigan_aishell3_ckpt_0.2.0/feats_stats.npy \
|
||||
--lang=canton \
|
||||
--text=${BIN_DIR}/../sentences_canton.txt \
|
||||
--output_dir=${train_output_path}/test_e2e \
|
||||
--phones_dict=dump/phone_id_map.txt \
|
||||
--speaker_dict=dump/speaker_id_map.txt \
|
||||
--spk_id=0 \
|
||||
--inference_dir=${train_output_path}/inference
|
||||
fi
|
@ -0,0 +1,7 @@
|
||||
001 白云山爬过一次嘅,好远啊,爬上去都成两个钟
|
||||
002 睇书咯,番屋企,而家好多人好少睇书噶喎
|
||||
003 因为如果唔考试嘅话,工资好低噶
|
||||
004 冇固定噶,你中意休边日就边日噶
|
||||
005 即系太迟嘅话咧,落班太迟嘅话就喺出边食啲咯
|
||||
006 是非有公理,慎言莫冒犯别人
|
||||
007 遇上冷风雨,休太认真
|
@ -0,0 +1,106 @@
|
||||
# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
from typing import Dict
|
||||
from typing import List
|
||||
|
||||
import numpy as np
|
||||
import paddle
|
||||
import ToJyutping
|
||||
|
||||
from paddlespeech.t2s.frontend.zh_normalization.text_normlization import TextNormalizer
|
||||
|
||||
INITIALS = [
|
||||
'p', 'b', 't', 'd', 'ts', 'dz', 'k', 'g', 'kw', 'gw', 'f', 'h', 'l', 'm',
|
||||
'ng', 'n', 's', 'y', 'w', 'c', 'z', 'j'
|
||||
]
|
||||
INITIALS += ['sp', 'spl', 'spn', 'sil']
|
||||
|
||||
|
||||
def get_lines(cantons: List[str]):
|
||||
phones = []
|
||||
for canton in cantons:
|
||||
for consonant in INITIALS:
|
||||
if canton.startswith(consonant):
|
||||
c, v = canton[:len(consonant)], canton[len(consonant):]
|
||||
phones = phones + [c, v]
|
||||
return phones
|
||||
|
||||
|
||||
class CantonFrontend():
|
||||
def __init__(self, phone_vocab_path: str):
|
||||
self.text_normalizer = TextNormalizer()
|
||||
self.punc = ":,;。?!“”‘’':,;.?!"
|
||||
|
||||
self.vocab_phones = {}
|
||||
if phone_vocab_path:
|
||||
with open(phone_vocab_path, 'rt', encoding='utf-8') as f:
|
||||
phn_id = [line.strip().split() for line in f.readlines()]
|
||||
for phn, id in phn_id:
|
||||
self.vocab_phones[phn] = int(id)
|
||||
|
||||
# if merge_sentences, merge all sentences into one phone sequence
|
||||
def _g2p(self, sentences: List[str],
|
||||
merge_sentences: bool=True) -> List[List[str]]:
|
||||
phones_list = []
|
||||
for sentence in sentences:
|
||||
phones_str = ToJyutping.get_jyutping_text(sentence)
|
||||
phones_split = get_lines(phones_str.split(' '))
|
||||
phones_list.append(phones_split)
|
||||
return phones_list
|
||||
|
||||
def _p2id(self, phonemes: List[str]) -> np.ndarray:
|
||||
# replace unk phone with sp
|
||||
phonemes = [
|
||||
phn if phn in self.vocab_phones else "sp" for phn in phonemes
|
||||
]
|
||||
phone_ids = [self.vocab_phones[item] for item in phonemes]
|
||||
return np.array(phone_ids, np.int64)
|
||||
|
||||
def get_phonemes(self,
|
||||
sentence: str,
|
||||
merge_sentences: bool=True,
|
||||
print_info: bool=False) -> List[List[str]]:
|
||||
sentences = self.text_normalizer.normalize(sentence)
|
||||
phonemes = self._g2p(sentences, merge_sentences=merge_sentences)
|
||||
if print_info:
|
||||
print("----------------------------")
|
||||
print("text norm results:")
|
||||
print(sentences)
|
||||
print("----------------------------")
|
||||
print("g2p results:")
|
||||
print(phonemes)
|
||||
print("----------------------------")
|
||||
return phonemes
|
||||
|
||||
def get_input_ids(self,
|
||||
sentence: str,
|
||||
merge_sentences: bool=True,
|
||||
print_info: bool=False,
|
||||
to_tensor: bool=True) -> Dict[str, List[paddle.Tensor]]:
|
||||
|
||||
phonemes = self.get_phonemes(
|
||||
sentence, merge_sentences=merge_sentences, print_info=print_info)
|
||||
result = {}
|
||||
temp_phone_ids = []
|
||||
|
||||
for phones in phonemes:
|
||||
if phones:
|
||||
phone_ids = self._p2id(phones)
|
||||
# if use paddle.to_tensor() in onnxruntime, the first time will be too low
|
||||
if to_tensor:
|
||||
phone_ids = paddle.to_tensor(phone_ids)
|
||||
temp_phone_ids.append(phone_ids)
|
||||
if temp_phone_ids:
|
||||
result["phone_ids"] = temp_phone_ids
|
||||
return result
|
Loading…
Reference in new issue