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
|
from typing import Dict
|
||||||
|
|
||||||
import dashscope
|
import dashscope
|
||||||
from dashscope.audio.tts_v2 import *
|
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
|
|
||||||
from common.util.common import _remove_empty_lines
|
from common.util.common import _remove_empty_lines
|
||||||
@ -38,8 +38,13 @@ class AliyunBaiLianTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
|
|
||||||
def text_to_speech(self, text):
|
def text_to_speech(self, text):
|
||||||
dashscope.api_key = self.api_key
|
dashscope.api_key = self.api_key
|
||||||
synthesizer = SpeechSynthesizer(model=self.model, **self.params)
|
|
||||||
text = _remove_empty_lines(text)
|
text = _remove_empty_lines(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)
|
audio = synthesizer.call(text)
|
||||||
if type(audio) == str:
|
if type(audio) == str:
|
||||||
print(audio)
|
print(audio)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user