update:优化docker-compose

This commit is contained in:
hrz
2025-02-14 23:09:12 +08:00
parent c59f24d1f7
commit c8c75df890
5 changed files with 58 additions and 18 deletions
+5
View File
@@ -31,9 +31,14 @@ prompt: |
你是一个叫小智/小志的台湾女孩,说话机车,声音好听,习惯简短表达,爱用网络梗。
请注意,要像一个人一样说话,请不要回复表情符号、代码、和xml标签。
当前时间是:{date_time},现在我正在和你进行语音聊天,我们开始吧。
如果用户希望结束对话,请在最后说“拜拜”或“再见”。
# 使用完声音文件后删除文件(Delete the sound file when you are done using it)
delete_audio: true
CMD_exit:
- "退出"
- "关闭"
# 具体处理时选择的模块(The module selected for specific processing)
selected_module:
ASR: FunASR
+11 -5
View File
@@ -68,19 +68,25 @@ class ConnectionHandler:
self.tts_start_speak_time = None
self.tts_duration = 0
self.cmd_exit = self.config["CMD_exit"]
self.max_cmd_length = 0
for cmd in self.cmd_exit:
if len(cmd) > self.max_cmd_length:
self.max_cmd_length = len(cmd)
async def handle_connection(self, ws):
try:
# 获取并验证headers
self.headers = dict(ws.request.headers)
self.logger.info(f"New connection request - Headers: {self.headers}")
# 进行认证
await self.auth.authenticate(self.headers)
# 认证通过,继续处理
self.websocket = ws
self.session_id = str(uuid.uuid4())
self.welcome_msg = self.config["xiaozhi"]
self.welcome_msg["session_id"] = self.session_id
await self.websocket.send(json.dumps(self.welcome_msg))
@@ -96,7 +102,7 @@ class ConnectionHandler:
except websockets.exceptions.ConnectionClosed:
self.logger.info("客户端断开连接")
await self.close()
except AuthenticationError as e:
self.logger.error(f"Authentication failed: {str(e)}")
await ws.close()
@@ -255,4 +261,4 @@ class ConnectionHandler:
while self.scheduled_tasks:
task = self.scheduled_tasks.popleft()
task.cancel()
self.scheduled_tasks.clear()
self.scheduled_tasks.clear()
+36 -2
View File
@@ -27,7 +27,10 @@ async def handleAudioMessage(conn, audio):
conn.asr_server_receive = False
text, file_path = conn.asr.speech_to_text(conn.asr_audio, conn.session_id)
logger.info(f"识别文本: {text}")
text_len = remove_punctuation_and_length(text)
text_len, text_without_punctuation = remove_punctuation_and_length(text)
if text_len <= conn.max_cmd_length and await handleCMDMessage(conn, text_without_punctuation):
return
if text_len > 0:
await startToChat(conn, text)
else:
@@ -36,6 +39,32 @@ async def handleAudioMessage(conn, audio):
conn.reset_vad_states()
async def handleCMDMessage(conn, text):
cmd_exit = conn.cmd_exit
for cmd in cmd_exit:
if text == cmd:
logger.info("识别到明确的退出命令".format(text))
await finishToChat(conn)
return True
return False
async def finishToChat(conn):
await conn.close()
async def isLLMWantToFinish(conn):
first_text = conn.tts_first_text
last_text = conn.tts_last_text
_, last_text_without_punctuation = remove_punctuation_and_length(last_text)
if "再见" in last_text_without_punctuation or "拜拜" in last_text_without_punctuation:
return True
_, first_text_without_punctuation = remove_punctuation_and_length(first_text)
if "再见" in first_text_without_punctuation or "拜拜" in first_text_without_punctuation:
return True
return False
async def startToChat(conn, text):
# 异步发送 stt 信息
stt_task = asyncio.create_task(
@@ -71,6 +100,11 @@ async def sendAudioMessage(conn, audios, duration, text):
schedule_with_interrupt(stop_duration, send_tts_message(conn, 'stop'))
)
conn.scheduled_tasks.append(stop_task)
if await isLLMWantToFinish(conn):
finish_task = asyncio.create_task(
schedule_with_interrupt(stop_duration, finishToChat(conn))
)
conn.scheduled_tasks.append(finish_task)
async def send_tts_message(conn, state, text=None):
@@ -112,4 +146,4 @@ async def schedule_with_interrupt(delay, coro):
await asyncio.sleep(delay)
await coro
except asyncio.CancelledError:
pass
pass
+3 -4
View File
@@ -5,9 +5,8 @@ import socket
def get_project_dir():
projectName = 'xiaozhi-esp32-server'
filePath = os.path.abspath(__file__)
return filePath[:filePath.rfind('/' + projectName + '/') + len(projectName) + 2]
"""获取项目根目录"""
return os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) + '/'
def get_local_ip():
@@ -91,4 +90,4 @@ def remove_punctuation_and_length(text):
if result == "Yeah":
return 0
return len(result)
return len(result), result
+3 -7
View File
@@ -1,15 +1,11 @@
services:
xiaozhi-esp32-server:
image: xiaozhi-esp32-server:0213
image: ccr.ccs.tencentyun.com/xinnan/xiaozhi-esp32-server:latest
container_name: xiaozhi-esp32-server
restart: always
#security_opt:
# - seccomp:unconfined
ports:
- "9005:8000"
- "8000:8000"
volumes:
- ./config.yaml:/opt/xiaozhi-es32-server/config.yaml
- ./models:/opt/xiaozhi-es32-server/models
- ./.config.yaml:/opt/xiaozhi-esp32-server/config.yaml