diff --git a/apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model/tts.py b/apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model/tts.py index ec26f14d5..bcba7d462 100644 --- a/apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model/tts.py +++ b/apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model/tts.py @@ -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)