mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-30 04:33:56 +08:00
fix: 修复流式TTS替换词显示/上报问题
This commit is contained in:
@@ -89,7 +89,7 @@ class TTSProvider(TTSProviderBase):
|
||||
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))
|
||||
asyncio.run(self.text_to_speak(text, original_text, is_last))
|
||||
except Exception as e:
|
||||
logger.bind(tag=TAG).warning(
|
||||
f"语音生成失败{5 - max_repeat_time + 1}次: {original_text},错误: {e}"
|
||||
@@ -109,9 +109,9 @@ class TTSProvider(TTSProviderBase):
|
||||
finally:
|
||||
return None
|
||||
|
||||
async def text_to_speak(self, text, is_last):
|
||||
async def text_to_speak(self, text, original_text, is_last):
|
||||
"""流式处理TTS音频,每句只推送一次音频列表"""
|
||||
await self._tts_request(text, is_last)
|
||||
await self._tts_request(text, original_text, is_last)
|
||||
|
||||
async def close(self):
|
||||
"""资源清理"""
|
||||
@@ -119,7 +119,7 @@ class TTSProvider(TTSProviderBase):
|
||||
if hasattr(self, "opus_encoder"):
|
||||
self.opus_encoder.close()
|
||||
|
||||
async def _tts_request(self, text: str, is_last: bool) -> None:
|
||||
async def _tts_request(self, text: str, original_text: str, is_last: bool) -> None:
|
||||
params = {
|
||||
"tts_text": text,
|
||||
"spk_id": self.voice,
|
||||
@@ -157,7 +157,7 @@ class TTSProvider(TTSProviderBase):
|
||||
return
|
||||
|
||||
self.pcm_buffer.clear()
|
||||
self.tts_audio_queue.put((SentenceType.FIRST, [], text))
|
||||
self.tts_audio_queue.put((SentenceType.FIRST, [], original_text))
|
||||
|
||||
# 兼容 iter_chunked / iter_chunks / iter_any
|
||||
async for chunk in resp.content.iter_any():
|
||||
|
||||
Reference in New Issue
Block a user