fix: fix the defect of empty line to speech error
--bug=1050760 --user=王孝刚 【应用】文本转语音使用豆包模型时,用户问题文本中间有空行,会报错 https://www.tapd.cn/57709429/s/1636230
This commit is contained in:
parent
037268179d
commit
32e5c8195a
@ -211,3 +211,7 @@ def split_and_transcribe(file_path, model, max_segment_length_ms=59000, audio_fo
|
|||||||
if isinstance(text, str):
|
if isinstance(text, str):
|
||||||
full_text.append(text)
|
full_text.append(text)
|
||||||
return ' '.join(full_text)
|
return ' '.join(full_text)
|
||||||
|
|
||||||
|
|
||||||
|
def _remove_empty_lines(text):
|
||||||
|
return '\n'.join(line for line in text.split('\n') if line.strip())
|
||||||
|
|||||||
@ -3,6 +3,7 @@ from typing import Dict
|
|||||||
import dashscope
|
import dashscope
|
||||||
from dashscope.audio.tts_v2 import *
|
from dashscope.audio.tts_v2 import *
|
||||||
|
|
||||||
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
|
|
||||||
@ -37,6 +38,7 @@ 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)
|
synthesizer = SpeechSynthesizer(model=self.model, **self.params)
|
||||||
|
text = _remove_empty_lines(text)
|
||||||
audio = synthesizer.call(text)
|
audio = synthesizer.call(text)
|
||||||
if type(audio) == str:
|
if type(audio) == str:
|
||||||
print(audio)
|
print(audio)
|
||||||
|
|||||||
@ -5,6 +5,7 @@ from dashscope.common.env import api_version
|
|||||||
from openai import OpenAI, AzureOpenAI
|
from openai import OpenAI, AzureOpenAI
|
||||||
|
|
||||||
from common.config.tokenizer_manage_config import TokenizerManage
|
from common.config.tokenizer_manage_config import TokenizerManage
|
||||||
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ class AzureOpenAITextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
api_key=self.api_key,
|
api_key=self.api_key,
|
||||||
api_version=self.api_version
|
api_version=self.api_version
|
||||||
)
|
)
|
||||||
|
text = _remove_empty_lines(text)
|
||||||
with client.audio.speech.with_streaming_response.create(
|
with client.audio.speech.with_streaming_response.create(
|
||||||
model=self.model,
|
model=self.model,
|
||||||
input=text,
|
input=text,
|
||||||
|
|||||||
@ -3,6 +3,7 @@ from typing import Dict
|
|||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
from common.config.tokenizer_manage_config import TokenizerManage
|
from common.config.tokenizer_manage_config import TokenizerManage
|
||||||
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
|
|
||||||
@ -51,6 +52,7 @@ class OpenAITextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
base_url=self.api_base,
|
base_url=self.api_base,
|
||||||
api_key=self.api_key
|
api_key=self.api_key
|
||||||
)
|
)
|
||||||
|
text = _remove_empty_lines(text)
|
||||||
with client.audio.speech.with_streaming_response.create(
|
with client.audio.speech.with_streaming_response.create(
|
||||||
model=self.model,
|
model=self.model,
|
||||||
input=text,
|
input=text,
|
||||||
|
|||||||
@ -18,6 +18,7 @@ from typing import Dict
|
|||||||
import ssl
|
import ssl
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
|
|
||||||
@ -95,6 +96,7 @@ class VolcanicEngineTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
"operation": "xxx"
|
"operation": "xxx"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
text = _remove_empty_lines(text)
|
||||||
|
|
||||||
return asyncio.run(self.submit(request_json, text))
|
return asyncio.run(self.submit(request_json, text))
|
||||||
|
|
||||||
|
|||||||
@ -18,6 +18,7 @@ from urllib.parse import urlencode, urlparse
|
|||||||
import ssl
|
import ssl
|
||||||
import websockets
|
import websockets
|
||||||
|
|
||||||
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
|
|
||||||
@ -102,6 +103,8 @@ class XFSparkTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
|
|
||||||
# 使用小语种须使用以下方式,此处的unicode指的是 utf16小端的编码方式,即"UTF-16LE"”
|
# 使用小语种须使用以下方式,此处的unicode指的是 utf16小端的编码方式,即"UTF-16LE"”
|
||||||
# self.Data = {"status": 2, "text": str(base64.b64encode(self.Text.encode('utf-16')), "UTF8")}
|
# self.Data = {"status": 2, "text": str(base64.b64encode(self.Text.encode('utf-16')), "UTF8")}
|
||||||
|
text = _remove_empty_lines(text)
|
||||||
|
|
||||||
async def handle():
|
async def handle():
|
||||||
async with websockets.connect(self.create_url(), max_size=1000000000, ssl=ssl_context) as ws:
|
async with websockets.connect(self.create_url(), max_size=1000000000, ssl=ssl_context) as ws:
|
||||||
# 发送 full client request
|
# 发送 full client request
|
||||||
|
|||||||
@ -3,6 +3,7 @@ from typing import Dict
|
|||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
|
||||||
from common.config.tokenizer_manage_config import TokenizerManage
|
from common.config.tokenizer_manage_config import TokenizerManage
|
||||||
|
from common.util.common import _remove_empty_lines
|
||||||
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
from setting.models_provider.base_model_provider import MaxKBBaseModel
|
||||||
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
from setting.models_provider.impl.base_tts import BaseTextToSpeech
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ class XInferenceTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
api_key=self.api_key
|
api_key=self.api_key
|
||||||
)
|
)
|
||||||
# ['中文女', '中文男', '日语男', '粤语女', '英文女', '英文男', '韩语女']
|
# ['中文女', '中文男', '日语男', '粤语女', '英文女', '英文男', '韩语女']
|
||||||
|
text = _remove_empty_lines(text)
|
||||||
with client.audio.speech.with_streaming_response.create(
|
with client.audio.speech.with_streaming_response.create(
|
||||||
model=self.model,
|
model=self.model,
|
||||||
input=text,
|
input=text,
|
||||||
|
|||||||
@ -429,9 +429,10 @@ const getPlatformConfig: (application_id: string, type: string) => Promise<Resul
|
|||||||
const updatePlatformConfig: (
|
const updatePlatformConfig: (
|
||||||
application_id: string,
|
application_id: string,
|
||||||
type: string,
|
type: string,
|
||||||
data: any
|
data: any,
|
||||||
) => Promise<Result<any>> = (application_id, type, data) => {
|
loading?: Ref<boolean>
|
||||||
return post(`/platform/${application_id}/${type}`, data)
|
) => Promise<Result<any>> = (application_id, type, data, loading) => {
|
||||||
|
return post(`/platform/${application_id}/${type}`, data, undefined, loading)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* 更新平台状态
|
* 更新平台状态
|
||||||
|
|||||||
@ -222,10 +222,13 @@ const submit = async () => {
|
|||||||
formRef.value?.validate(async (valid) => {
|
formRef.value?.validate(async (valid) => {
|
||||||
if (valid) {
|
if (valid) {
|
||||||
try {
|
try {
|
||||||
await applicationApi.updatePlatformConfig(id, configType.value, form[configType.value])
|
applicationApi
|
||||||
MsgSuccess('配置保存成功')
|
.updatePlatformConfig(id, configType.value, form[configType.value], loading)
|
||||||
closeDrawer()
|
.then(() => {
|
||||||
emit('refresh')
|
MsgSuccess('配置保存成功')
|
||||||
|
closeDrawer()
|
||||||
|
emit('refresh')
|
||||||
|
})
|
||||||
} catch {
|
} catch {
|
||||||
MsgError('保存失败,请检查输入或稍后再试')
|
MsgError('保存失败,请检查输入或稍后再试')
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user