mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-11-28 04:59:52 +01:00
commit
cea5d51c60
4 changed files with 28 additions and 30 deletions
|
|
@ -32,6 +32,33 @@ services:
|
|||
- REGION=LOCAL
|
||||
healthcheck:
|
||||
disable: true
|
||||
# 容器启动时自动获取公网 IP 并设置环境变量(使用 Python,无需 curl)
|
||||
command:
|
||||
- sh
|
||||
- -c
|
||||
- |
|
||||
get_public_ip() {
|
||||
python3 -c "
|
||||
import urllib.request
|
||||
def get_ip():
|
||||
for url, timeout in [('http://169.254.169.254/latest/meta-data/public-ipv4',2),('https://ifconfig.me',3),('https://api.ipify.org',3)]:
|
||||
try:
|
||||
req = urllib.request.Request(url, headers={'User-Agent': 'curl/7.68.0'})
|
||||
with urllib.request.urlopen(req, timeout=timeout) as r:
|
||||
ip = r.read().decode().strip()
|
||||
if ip: return ip
|
||||
except: pass
|
||||
return 'localhost'
|
||||
print(get_ip())
|
||||
"
|
||||
}
|
||||
export PUBLIC_IP=$$(get_public_ip)
|
||||
export WEBSOCKET_URL="ws://$${PUBLIC_IP}:8000/xiaozhi/v1/"
|
||||
export OTA_URL="http://$${PUBLIC_IP}:8003/xiaozhi/ota/"
|
||||
echo ">>> Detected PUBLIC_IP: $${PUBLIC_IP}"
|
||||
echo ">>> WEBSOCKET_URL: $${WEBSOCKET_URL}"
|
||||
echo ">>> OTA_URL: $${OTA_URL}"
|
||||
exec python app.py
|
||||
volumes:
|
||||
# Configuration directory
|
||||
- /home/ubuntu/live-agent/main/xiaozhi-server/data:/opt/xiaozhi-esp32-server/data
|
||||
|
|
|
|||
|
|
@ -47,9 +47,7 @@ async def sendAudioMessage(conn, sentenceType, audios, text, message_tag=Message
|
|||
conn.logger.bind(tag=TAG).info(f"发送音频消息: {sentenceType}, {text}")
|
||||
|
||||
# 发送结束消息(如果是最后一个文本)
|
||||
# 条件1: llm_finish_task=True 且 LAST (正常结束)
|
||||
# 条件2: LAST 且 MOCK (超时触发的结束)
|
||||
if (conn.llm_finish_task and sentenceType == SentenceType.LAST) or (sentenceType == SentenceType.LAST and message_tag == MessageTag.MOCK):
|
||||
if conn.llm_finish_task and sentenceType == SentenceType.LAST:
|
||||
await send_tts_message(conn, "stop", None, message_tag)
|
||||
conn.client_is_speaking = False
|
||||
if conn.close_after_chat:
|
||||
|
|
|
|||
|
|
@ -27,7 +27,6 @@ class MessageTag(Enum):
|
|||
NORMAL = 0
|
||||
OPENING = 1
|
||||
CLOSING = 2
|
||||
MOCK = 3
|
||||
|
||||
|
||||
class TTSMessageDTO:
|
||||
|
|
|
|||
|
|
@ -261,21 +261,12 @@ class TTSProvider(TTSProviderBase):
|
|||
# 用于跟踪上一个发送任务,确保顺序但不阻塞
|
||||
last_send_future = None
|
||||
|
||||
# 超时检测相关变量
|
||||
last_message_time = time.time() # 最后一次成功拉取消息的时间
|
||||
timeout_last_sent = False # 是否已经因为超时发送过 LAST 消息
|
||||
IDLE_TIMEOUT = 1.0 # 超时阈值(秒)
|
||||
|
||||
while not self.conn.stop_event.is_set():
|
||||
text = None
|
||||
report_time = None
|
||||
try:
|
||||
try:
|
||||
tts_audio_message = self.tts_audio_queue.get_nowait()
|
||||
|
||||
# 成功拉取到消息,重置 timer 和 flag
|
||||
last_message_time = time.time()
|
||||
timeout_last_sent = False
|
||||
|
||||
if isinstance(tts_audio_message, TTSAudioDTO):
|
||||
sentence_type = tts_audio_message.sentence_type
|
||||
|
|
@ -295,23 +286,6 @@ class TTSProvider(TTSProviderBase):
|
|||
except queue.Empty:
|
||||
if self.conn.stop_event.is_set():
|
||||
break
|
||||
|
||||
# 超时检测:如果超过 IDLE_TIMEOUT 没有拉取到消息,放入一条 MOCK LAST 消息
|
||||
if not timeout_last_sent and (time.time() - last_message_time) > IDLE_TIMEOUT:
|
||||
logger.bind(tag=TAG).debug(
|
||||
f"Audio queue idle for {IDLE_TIMEOUT}s, putting timeout LAST message"
|
||||
)
|
||||
# 往队列放入 MOCK LAST 消息,由正常流程处理
|
||||
self.tts_audio_queue.put(TTSAudioDTO(
|
||||
sentence_type=SentenceType.LAST,
|
||||
audio_data=None,
|
||||
text=None,
|
||||
message_tag=MessageTag.MOCK,
|
||||
))
|
||||
# 设置 flag,不再重复放入
|
||||
timeout_last_sent = True
|
||||
# timer 不清零,保持原值
|
||||
|
||||
continue
|
||||
|
||||
if self.conn.client_abort:
|
||||
|
|
|
|||
Loading…
Reference in a new issue