mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 05:13:59 +08:00
update:替换词功能
This commit is contained in:
@@ -84,22 +84,25 @@ class TTSProvider(TTSProviderBase):
|
||||
def to_tts_single_stream(self, text, is_last=False):
|
||||
try:
|
||||
max_repeat_time = 5
|
||||
original_text = text
|
||||
text = MarkdownCleaner.clean_markdown(text)
|
||||
if self._correct_words_pattern:
|
||||
text = self._correct_words_pattern.sub(lambda m: self.correct_words[m.group(0)], text)
|
||||
try:
|
||||
asyncio.run(self.text_to_speak(text, is_last))
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).warning(
|
||||
f"语音生成失败{5 - max_repeat_time + 1}次: {text},错误: {e}"
|
||||
f"语音生成失败{5 - max_repeat_time + 1}次: {original_text},错误: {e}"
|
||||
)
|
||||
max_repeat_time -= 1
|
||||
|
||||
if max_repeat_time > 0:
|
||||
logger.bind(tag=TAG).info(
|
||||
f"语音生成成功: {text},重试{5 - max_repeat_time}次"
|
||||
f"语音生成成功: {original_text},重试{5 - max_repeat_time}次"
|
||||
)
|
||||
else:
|
||||
logger.bind(tag=TAG).error(
|
||||
f"语音生成失败: {text},请检查网络或服务是否正常"
|
||||
f"语音生成失败: {original_text},请检查网络或服务是否正常"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).error(f"Failed to generate TTS file: {e}")
|
||||
@@ -202,6 +205,8 @@ class TTSProvider(TTSProviderBase):
|
||||
"""
|
||||
start_time = time.time()
|
||||
text = MarkdownCleaner.clean_markdown(text)
|
||||
if self._correct_words_pattern:
|
||||
text = self._correct_words_pattern.sub(lambda m: self.correct_words[m.group(0)], text)
|
||||
|
||||
params = {
|
||||
"tts_text": text,
|
||||
|
||||
Reference in New Issue
Block a user