From 13ce64e51a4094798d54b9f95b3eaeb4b012c780 Mon Sep 17 00:00:00 2001 From: CaptainB Date: Tue, 4 Mar 2025 10:42:09 +0800 Subject: [PATCH] fix: Compatible with dashscope tts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1052708 --user=刘瑞斌 【应用】-使用阿里云语音合成模型sambert-zhichu-v1,对话报错 https://www.tapd.cn/57709429/s/1661551 --- .../impl/aliyun_bai_lian_model_provider/model/tts.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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)