Skip to content

Commit

Permalink
fix: 修复豆包语音合成不能处理全字符文本的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
liuruibin committed Oct 28, 2024
1 parent 4b9253f commit da37338
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import copy
import gzip
import json
import re
import uuid
from typing import Dict
import ssl
Expand Down Expand Up @@ -112,6 +113,8 @@ async def submit(self, request_json, text):
ssl=ssl_context) as ws:
lines = text.split('\n')
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"]["text"] = line
payload_bytes = str.encode(json.dumps(submit_request_json))
Expand All @@ -123,6 +126,11 @@ async def submit(self, request_json, text):
result += await self.parse_response(ws)
return result

@staticmethod
def is_table_format_chars_only(s):
# 检查是否仅包含 "|", "-", 和空格字符
return bool(s) and re.fullmatch(r'[|\-\s]+', s)

@staticmethod
async def parse_response(ws):
result = b''
Expand Down

0 comments on commit da37338

Please sign in to comment.