mirror of
https://github.com/1Panel-dev/MaxKB.git
synced 2025-12-26 01:33:05 +00:00
fix: Compatible with dashscope tts
--bug=1052708 --user=刘瑞斌 【应用】-使用阿里云语音合成模型sambert-zhichu-v1,对话报错 https://www.tapd.cn/57709429/s/1661551
This commit is contained in:
parent
5e563054f9
commit
13ce64e51a
|
|
@ -1,7 +1,7 @@
|
|||
from typing import Dict
|
||||
|
||||
import dashscope
|
||||
from dashscope.audio.tts_v2 import *
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from common.util.common import _remove_empty_lines
|
||||
|
|
@ -38,9 +38,14 @@ class AliyunBaiLianTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||
|
||||
def text_to_speech(self, text):
|
||||
dashscope.api_key = self.api_key
|
||||
synthesizer = SpeechSynthesizer(model=self.model, **self.params)
|
||||
text = _remove_empty_lines(text)
|
||||
audio = synthesizer.call(text)
|
||||
if 'sambert' in self.model:
|
||||
from dashscope.audio.tts import SpeechSynthesizer
|
||||
audio = SpeechSynthesizer.call(model=self.model, text=text, **self.params).get_audio_data()
|
||||
else:
|
||||
from dashscope.audio.tts_v2 import SpeechSynthesizer
|
||||
synthesizer = SpeechSynthesizer(model=self.model, **self.params)
|
||||
audio = synthesizer.call(text)
|
||||
if type(audio) == str:
|
||||
print(audio)
|
||||
raise Exception(audio)
|
||||
|
|
|
|||
Loading…
Reference in New Issue