mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-29 05:13:56 +08:00
update:旧非流失兼容改造
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import asyncio
|
||||
import time
|
||||
from core.providers.tts.dto.dto import SentenceType
|
||||
from core.utils.util import get_string_no_punctuation_or_emoji, analyze_emotion
|
||||
|
||||
TAG = __name__
|
||||
@@ -30,7 +31,7 @@ emoji_map = {
|
||||
}
|
||||
|
||||
|
||||
async def sendAudioMessage(conn, audios, text, text_index=0):
|
||||
async def sendAudioMessage(conn, sentenceType, audios, text):
|
||||
# 发送句子开始消息
|
||||
if text is not None:
|
||||
emotion = analyze_emotion(text)
|
||||
@@ -46,25 +47,24 @@ async def sendAudioMessage(conn, audios, text, text_index=0):
|
||||
)
|
||||
)
|
||||
|
||||
if text_index == conn.tts_first_text_index:
|
||||
conn.logger.bind(tag=TAG).info(f"发送第一段语音: {text}")
|
||||
await send_tts_message(conn, "sentence_start", text)
|
||||
|
||||
is_first_audio = text_index == conn.tts_first_text_index
|
||||
await sendAudio(conn, audios, pre_buffer=is_first_audio)
|
||||
await sendAudio(conn, audios, True)
|
||||
|
||||
await send_tts_message(conn, "sentence_end", text)
|
||||
|
||||
# 发送结束消息(如果是最后一个文本)
|
||||
if conn.llm_finish_task and text_index == conn.tts_last_text_index:
|
||||
if conn.llm_finish_task and sentenceType == SentenceType.LAST:
|
||||
await send_tts_message(conn, "stop", None)
|
||||
await conn.tts.finish_session(conn.tts_session_id)
|
||||
await conn.tts.finish_session(conn.sentence_id)
|
||||
if conn.close_after_chat:
|
||||
await conn.close()
|
||||
|
||||
|
||||
# 播放音频
|
||||
async def sendAudio(conn, audios, pre_buffer=True):
|
||||
if audios is None or len(audios) == 0:
|
||||
return
|
||||
# 流控参数优化
|
||||
frame_duration = 60 # 帧时长(毫秒),匹配 Opus 编码
|
||||
start_time = time.perf_counter()
|
||||
|
||||
Reference in New Issue
Block a user