-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TTS]Cantonese FastSpeech2 e2e infer, test=tts #2927
Merged
Merged
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
f90e242
Merge branch 'PaddlePaddle:develop' into develop
WongLaw b2597bc
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 0ab03d8
Merge branch 'PaddlePaddle:develop' into develop
WongLaw a20ca46
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 26a6fb5
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 0cee810
Add rhythm tags for MFA, test=tts
WongLaw d7e2931
Add rhythm tags for MFA, test=tts
WongLaw 832ff0e
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 7939884
Revised Rhythm label for MFA, test=tts
WongLaw 05447ea
Merge branch 'PaddlePaddle:develop' into develop
WongLaw f28d0a1
Merge branch 'PaddlePaddle:develop' into develop
WongLaw a6adcc4
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 696ee80
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 5525468
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 2430e13
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 0ab7fb0
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 859e8d2
Merge branch 'PaddlePaddle:develop' into develop
WongLaw 3131c9b
Cantonese FastSpeech2 Training, test=tts
WongLaw 4f144fa
Cantonese FastSpeech2 Training, test=tts
WongLaw 2016080
Cantonese FastSpeech2 Training, test=tts
WongLaw eff42a4
Cantonese FastSpeech2 Training, test=tts
WongLaw e79f0a6
Cantonese FastSpeech2 Training, test=tts
WongLaw 22f8a09
Cantonese FastSpeech2 Training, test=tts
WongLaw 599f325
Cantonese FastSpeech2 Training, test=tts
WongLaw 54629d3
Cantonese FastSpeech2 Training, test=tts
WongLaw b415723
Cantonese FastSpeech2 Training, test=tts
WongLaw 2e825a4
Cantonese FastSpeech2 e2e infer, test=tts
WongLaw db7e651
Merge branch 'develop' into canton_model
WongLaw 8ba2e61
Cantonese FastSpeech2 e2e infer, test=tts
WongLaw 668a1ee
Merge branch 'PaddlePaddle:develop' into canton_model
WongLaw d3cd1b9
Merge branch 'canton_model' of https://github.com/WongLaw/PaddleSpeec…
WongLaw aafff71
Cantonese FastSpeech2 e2e infer, test=tts
WongLaw 9c4341a
Cantonese FastSpeech2 e2e infer, test=tts
WongLaw 8bd9991
Cantonese FastSpeech2 e2e infer, test=tts
WongLaw e731d69
Cantonese FastSpeech2 e2e infer, test=tts
WongLaw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=zh \ | ||
yt605155624 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
--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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
001 白云山爬过一次嘅,好远啊,爬上去都成两个钟 | ||
002 睇书咯,番屋企,而家好多人好少睇书噶喎 | ||
003 因为如果唔考试嘅话,工资好低噶 | ||
004 冇固定噶,你中意休边日就边日噶 | ||
005 即系太迟嘅话咧,落班太迟嘅话就喺出边食啲咯 | ||
006 是非有公理,慎言莫冒犯别人 | ||
007 遇上冷风雨,休太认真 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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): | ||
yt605155624 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里不用改了