|
|
|
@ -14,9 +14,11 @@
|
|
|
|
|
import argparse
|
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
|
|
|
|
import numpy
|
|
|
|
|
import soundfile as sf
|
|
|
|
|
from paddle import inference
|
|
|
|
|
|
|
|
|
|
from paddlespeech.t2s.frontend import English
|
|
|
|
|
from paddlespeech.t2s.frontend.zh_frontend import Frontend
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -29,20 +31,38 @@ def main():
|
|
|
|
|
'--am',
|
|
|
|
|
type=str,
|
|
|
|
|
default='fastspeech2_csmsc',
|
|
|
|
|
choices=['speedyspeech_csmsc', 'fastspeech2_csmsc'],
|
|
|
|
|
choices=[
|
|
|
|
|
'speedyspeech_csmsc', 'fastspeech2_csmsc', 'fastspeech2_aishell3',
|
|
|
|
|
'fastspeech2_vctk'
|
|
|
|
|
],
|
|
|
|
|
help='Choose acoustic model type of tts task.')
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--phones_dict", type=str, default=None, help="phone vocabulary file.")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--tones_dict", type=str, default=None, help="tone vocabulary file.")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--speaker_dict", type=str, default=None, help="speaker id map file.")
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--spk_id',
|
|
|
|
|
type=int,
|
|
|
|
|
default=0,
|
|
|
|
|
help='spk id for multi speaker acoustic model')
|
|
|
|
|
# voc
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--voc',
|
|
|
|
|
type=str,
|
|
|
|
|
default='pwgan_csmsc',
|
|
|
|
|
choices=['pwgan_csmsc', 'mb_melgan_csmsc', 'hifigan_csmsc'],
|
|
|
|
|
choices=[
|
|
|
|
|
'pwgan_csmsc', 'mb_melgan_csmsc', 'hifigan_csmsc', 'pwgan_aishell3',
|
|
|
|
|
'pwgan_vctk'
|
|
|
|
|
],
|
|
|
|
|
help='Choose vocoder type of tts task.')
|
|
|
|
|
# other
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
'--lang',
|
|
|
|
|
type=str,
|
|
|
|
|
default='zh',
|
|
|
|
|
help='Choose model language. zh or en')
|
|
|
|
|
parser.add_argument(
|
|
|
|
|
"--text",
|
|
|
|
|
type=str,
|
|
|
|
@ -53,8 +73,12 @@ def main():
|
|
|
|
|
|
|
|
|
|
args, _ = parser.parse_known_args()
|
|
|
|
|
|
|
|
|
|
frontend = Frontend(
|
|
|
|
|
phone_vocab_path=args.phones_dict, tone_vocab_path=args.tones_dict)
|
|
|
|
|
# frontend
|
|
|
|
|
if args.lang == 'zh':
|
|
|
|
|
frontend = Frontend(
|
|
|
|
|
phone_vocab_path=args.phones_dict, tone_vocab_path=args.tones_dict)
|
|
|
|
|
elif args.lang == 'en':
|
|
|
|
|
frontend = English(phone_vocab_path=args.phones_dict)
|
|
|
|
|
print("frontend done!")
|
|
|
|
|
|
|
|
|
|
# model: {model_name}_{dataset}
|
|
|
|
@ -83,30 +107,52 @@ def main():
|
|
|
|
|
|
|
|
|
|
print("in new inference")
|
|
|
|
|
|
|
|
|
|
# construct dataset for evaluation
|
|
|
|
|
sentences = []
|
|
|
|
|
with open(args.text, 'rt') as f:
|
|
|
|
|
for line in f:
|
|
|
|
|
items = line.strip().split()
|
|
|
|
|
utt_id = items[0]
|
|
|
|
|
sentence = "".join(items[1:])
|
|
|
|
|
if args.lang == 'zh':
|
|
|
|
|
sentence = "".join(items[1:])
|
|
|
|
|
elif args.lang == 'en':
|
|
|
|
|
sentence = " ".join(items[1:])
|
|
|
|
|
sentences.append((utt_id, sentence))
|
|
|
|
|
|
|
|
|
|
get_tone_ids = False
|
|
|
|
|
if am_name == 'speedyspeech':
|
|
|
|
|
get_tone_ids = True
|
|
|
|
|
if am_dataset in {"aishell3", "vctk"} and args.speaker_dict:
|
|
|
|
|
get_spk_id = True
|
|
|
|
|
spk_id = numpy.array([args.spk_id])
|
|
|
|
|
|
|
|
|
|
am_input_names = am_predictor.get_input_names()
|
|
|
|
|
|
|
|
|
|
print("am_input_names:", am_input_names)
|
|
|
|
|
merge_sentences = True
|
|
|
|
|
for utt_id, sentence in sentences:
|
|
|
|
|
input_ids = frontend.get_input_ids(
|
|
|
|
|
sentence, merge_sentences=True, get_tone_ids=get_tone_ids)
|
|
|
|
|
phone_ids = input_ids["phone_ids"]
|
|
|
|
|
if args.lang == 'zh':
|
|
|
|
|
input_ids = frontend.get_input_ids(
|
|
|
|
|
sentence,
|
|
|
|
|
merge_sentences=merge_sentences,
|
|
|
|
|
get_tone_ids=get_tone_ids)
|
|
|
|
|
phone_ids = input_ids["phone_ids"]
|
|
|
|
|
elif args.lang == 'en':
|
|
|
|
|
input_ids = frontend.get_input_ids(
|
|
|
|
|
sentence, merge_sentences=merge_sentences)
|
|
|
|
|
phone_ids = input_ids["phone_ids"]
|
|
|
|
|
else:
|
|
|
|
|
print("lang should in {'zh', 'en'}!")
|
|
|
|
|
|
|
|
|
|
if get_tone_ids:
|
|
|
|
|
tone_ids = input_ids["tone_ids"]
|
|
|
|
|
tones = tone_ids[0].numpy()
|
|
|
|
|
tones_handle = am_predictor.get_input_handle(am_input_names[1])
|
|
|
|
|
tones_handle.reshape(tones.shape)
|
|
|
|
|
tones_handle.copy_from_cpu(tones)
|
|
|
|
|
|
|
|
|
|
if get_spk_id:
|
|
|
|
|
spk_id_handle = am_predictor.get_input_handle(am_input_names[1])
|
|
|
|
|
spk_id_handle.reshape(spk_id.shape)
|
|
|
|
|
spk_id_handle.copy_from_cpu(spk_id)
|
|
|
|
|
phones = phone_ids[0].numpy()
|
|
|
|
|
phones_handle = am_predictor.get_input_handle(am_input_names[0])
|
|
|
|
|
phones_handle.reshape(phones.shape)
|
|
|
|
|