from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks
from modelscope.outputs import OutputKeys
model_id = 'damo/speech_sambert-hifigan_tts_zh-cn_16k'
sambert_hifigan_tts = pipeline(task=Tasks.text_to_speech, model=model_id)
#2、生成wav1
text1 = '第一句'
output = sambert_hifigan_tts(input=text1, voice='zhitian_emo')
wav1 = output[OutputKeys.OUTPUT_WAV]
with open('output1.wav', 'wb') as f:
f.write(wav1)
#3、生成wav2
text2 = '这是第二句'
output = sambert_hifigan_tts(input=text2, voice='zhitian_emo')
wav2 = output[OutputKeys.OUTPUT_WAV]
with open('output2.wav', 'wb') as f:
f.write(wav2)
#4、处理拼接
import soundfile as sf
import io
import numpy as np
bytes_content1 = io.BytesIO(wav1)
bytes_content2 = io.BytesIO(wav2)
datas=[]
bytes_content=wav1
data1, samplerate1 = sf.read(bytes_content1)
datas.append(data1)
data2, samplerate = sf.read(bytes_content2)
datas.append(data2)
combined = np.concatenate(datas)
print(combined)
out_ret = io.BytesIO()
sf.write(out_ret, combined, samplerate=samplerate, format="wav")
#5、生成的结果wav3
import IPython.display as ipd
wav3=out_ret.getvalue()
ipd.Audio(wav3)
--Mr.west