2022-06-20 17:23:11 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
import tensorflow as tf
|
|
|
|
|
# NOTICE: Tensorflow 1.15 seems not so compatible with pytorch.
|
|
|
|
|
# A segmentation fault may be raise by pytorch cpp library
|
|
|
|
|
# if 'import tensorflow' in front of 'import torch'.
|
|
|
|
|
# Puting a 'import torch' here can bypass this incompatibility.
|
|
|
|
|
import torch
|
|
|
|
|
from scipy.io.wavfile import write
|
|
|
|
|
|
2022-06-22 14:15:32 +08:00
|
|
|
from modelscope.metainfo import Pipelines, Preprocessors
|
2022-06-23 16:55:48 +08:00
|
|
|
from modelscope.models import Model
|
2022-06-20 17:23:11 +08:00
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.preprocessors import build_preprocessor
|
2022-06-23 16:55:48 +08:00
|
|
|
from modelscope.utils.constant import Fields
|
2022-06-20 17:23:11 +08:00
|
|
|
from modelscope.utils.logger import get_logger
|
2022-06-23 16:55:48 +08:00
|
|
|
from modelscope.utils.test_utils import test_level
|
2022-06-20 17:23:11 +08:00
|
|
|
|
|
|
|
|
logger = get_logger()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TextToSpeechSambertHifigan16kPipelineTest(unittest.TestCase):
|
|
|
|
|
|
2022-06-23 16:55:48 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
2022-06-20 17:23:11 +08:00
|
|
|
def test_pipeline(self):
|
|
|
|
|
lang_type = 'pinyin'
|
|
|
|
|
text = '明天天气怎么样'
|
|
|
|
|
preprocessor_model_id = 'damo/speech_binary_tts_frontend_resource'
|
|
|
|
|
am_model_id = 'damo/speech_sambert16k_tts_zhitian_emo'
|
|
|
|
|
voc_model_id = 'damo/speech_hifigan16k_tts_zhitian_emo'
|
|
|
|
|
|
|
|
|
|
cfg_preprocessor = dict(
|
2022-06-22 14:15:32 +08:00
|
|
|
type=Preprocessors.text_to_tacotron_symbols,
|
2022-06-20 17:23:11 +08:00
|
|
|
model_name=preprocessor_model_id,
|
|
|
|
|
lang_type=lang_type)
|
|
|
|
|
preprocessor = build_preprocessor(cfg_preprocessor, Fields.audio)
|
|
|
|
|
self.assertTrue(preprocessor is not None)
|
|
|
|
|
|
|
|
|
|
am = Model.from_pretrained(am_model_id)
|
|
|
|
|
self.assertTrue(am is not None)
|
|
|
|
|
|
|
|
|
|
voc = Model.from_pretrained(voc_model_id)
|
|
|
|
|
self.assertTrue(voc is not None)
|
|
|
|
|
|
|
|
|
|
sambert_tts = pipeline(
|
2022-06-22 14:15:32 +08:00
|
|
|
pipeline_name=Pipelines.sambert_hifigan_16k_tts,
|
2022-06-20 17:23:11 +08:00
|
|
|
config_file='',
|
|
|
|
|
model=[am, voc],
|
|
|
|
|
preprocessor=preprocessor)
|
|
|
|
|
self.assertTrue(sambert_tts is not None)
|
|
|
|
|
|
|
|
|
|
output = sambert_tts(text)
|
|
|
|
|
self.assertTrue(len(output['output']) > 0)
|
|
|
|
|
write('output.wav', 16000, output['output'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|