Skip to content

Commit 13ce64e

Browse files
committed
fix: Compatible with dashscope tts
--bug=1052708 --user=刘瑞斌 【应用】-使用阿里云语音合成模型sambert-zhichu-v1,对话报错 https://www.tapd.cn/57709429/s/1661551
1 parent 5e56305 commit 13ce64e

File tree

1 file changed

+8
-3
lines changed
  • apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model

1 file changed

+8
-3
lines changed

apps/setting/models_provider/impl/aliyun_bai_lian_model_provider/model/tts.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from typing import Dict
22

33
import dashscope
4-
from dashscope.audio.tts_v2 import *
4+
55
from django.utils.translation import gettext as _
66

77
from common.util.common import _remove_empty_lines
@@ -38,9 +38,14 @@ def check_auth(self):
3838

3939
def text_to_speech(self, text):
4040
dashscope.api_key = self.api_key
41-
synthesizer = SpeechSynthesizer(model=self.model, **self.params)
4241
text = _remove_empty_lines(text)
43-
audio = synthesizer.call(text)
42+
if 'sambert' in self.model:
43+
from dashscope.audio.tts import SpeechSynthesizer
44+
audio = SpeechSynthesizer.call(model=self.model, text=text, **self.params).get_audio_data()
45+
else:
46+
from dashscope.audio.tts_v2 import SpeechSynthesizer
47+
synthesizer = SpeechSynthesizer(model=self.model, **self.params)
48+
audio = synthesizer.call(text)
4449
if type(audio) == str:
4550
print(audio)
4651
raise Exception(audio)

0 commit comments

Comments
 (0)