2022-06-20 17:23:11 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
# 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-07-08 14:26:18 +08:00
|
|
|
from modelscope.metainfo import Pipelines
|
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
|
2022-07-08 14:26:18 +08:00
|
|
|
from modelscope.pipelines.outputs import OutputKeys
|
2022-07-01 17:27:55 +08:00
|
|
|
from modelscope.utils.constant import Fields, Tasks
|
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
|
|
|
|
2022-07-06 13:20:04 +08:00
|
|
|
import tensorflow as tf # isort:skip
|
|
|
|
|
|
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):
|
2022-07-08 14:26:18 +08:00
|
|
|
single_test_case_label = 'test_case_label_0'
|
|
|
|
|
text = '今天北京天气怎么样?'
|
2022-07-13 14:04:23 +08:00
|
|
|
model_id = 'damo/speech_sambert-hifigan_tts_zhcn_16k'
|
|
|
|
|
voice = 'zhitian_emo'
|
2022-07-08 14:26:18 +08:00
|
|
|
|
|
|
|
|
sambert_hifigan_tts = pipeline(
|
|
|
|
|
task=Tasks.text_to_speech, model=model_id)
|
|
|
|
|
self.assertTrue(sambert_hifigan_tts is not None)
|
2022-07-13 14:04:23 +08:00
|
|
|
inputs = {single_test_case_label: text, 'voice': voice}
|
|
|
|
|
output = sambert_hifigan_tts(inputs)
|
2022-07-08 14:26:18 +08:00
|
|
|
self.assertIsNotNone(output[OutputKeys.OUTPUT_PCM])
|
|
|
|
|
pcm = output[OutputKeys.OUTPUT_PCM][single_test_case_label]
|
|
|
|
|
write('output.wav', 16000, pcm)
|
2022-06-20 17:23:11 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|