fix: 修复豆包语音合成不能处理全字符文本的问题
This commit is contained in:
parent
4b9253f525
commit
da37338f7e
@ -12,6 +12,7 @@ import asyncio
|
|||||||
import copy
|
import copy
|
||||||
import gzip
|
import gzip
|
||||||
import json
|
import json
|
||||||
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
from typing import Dict
|
from typing import Dict
|
||||||
import ssl
|
import ssl
|
||||||
@ -112,6 +113,8 @@ class VolcanicEngineTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
ssl=ssl_context) as ws:
|
ssl=ssl_context) as ws:
|
||||||
lines = text.split('\n')
|
lines = text.split('\n')
|
||||||
for line in lines:
|
for line in lines:
|
||||||
|
if self.is_table_format_chars_only(line):
|
||||||
|
continue
|
||||||
submit_request_json["request"]["reqid"] = str(uuid.uuid4())
|
submit_request_json["request"]["reqid"] = str(uuid.uuid4())
|
||||||
submit_request_json["request"]["text"] = line
|
submit_request_json["request"]["text"] = line
|
||||||
payload_bytes = str.encode(json.dumps(submit_request_json))
|
payload_bytes = str.encode(json.dumps(submit_request_json))
|
||||||
@ -123,6 +126,11 @@ class VolcanicEngineTextToSpeech(MaxKBBaseModel, BaseTextToSpeech):
|
|||||||
result += await self.parse_response(ws)
|
result += await self.parse_response(ws)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def is_table_format_chars_only(s):
|
||||||
|
# 检查是否仅包含 "|", "-", 和空格字符
|
||||||
|
return bool(s) and re.fullmatch(r'[|\-\s]+', s)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def parse_response(ws):
|
async def parse_response(ws):
|
||||||
result = b''
|
result = b''
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user