diff --git a/.gitignore b/.gitignore index a25b3401..f6264b6d 100644 --- a/.gitignore +++ b/.gitignore @@ -145,6 +145,7 @@ tmp .history .DS_Store main/xiaozhi-server/data +!main/xiaozhi-server/data/tts_notify.mp3 main/manager-web/node_modules .config.yaml .secrets.yaml diff --git a/main/xiaozhi-server/config.yaml b/main/xiaozhi-server/config.yaml index 1d977aa1..dc6304ca 100644 --- a/main/xiaozhi-server/config.yaml +++ b/main/xiaozhi-server/config.yaml @@ -57,6 +57,10 @@ delete_audio: true close_connection_no_voice_time: 120 # TTS请求超时时间(秒) tts_timeout: 10 +# TTS播放结束提示音 +tts_notify: "data/tts_notify.mp3" +# 开场是否回复唤醒词 +enable_greeting: true CMD_exit: - "退出" diff --git a/main/xiaozhi-server/core/handle/sendAudioHandle.py b/main/xiaozhi-server/core/handle/sendAudioHandle.py index 8999bf08..545a9286 100644 --- a/main/xiaozhi-server/core/handle/sendAudioHandle.py +++ b/main/xiaozhi-server/core/handle/sendAudioHandle.py @@ -60,9 +60,19 @@ async def send_tts_message(conn, state, text=None): if text is not None: message["text"] = text - await conn.websocket.send(json.dumps(message)) + # TTS播放结束 if state == "stop": + # 清除服务端讲话状态 conn.clearSpeakStatus() + # 播放提示音 + tts_notify = conn.config.get("tts_notify", "") + if tts_notify: + opus_packets, duration = conn.tts.audio_to_opus_data(tts_notify) + for opus_packet in opus_packets: + await conn.websocket.send(opus_packet) + + # 发送消息到客户端 + await conn.websocket.send(json.dumps(message)) async def send_stt_message(conn, text): diff --git a/main/xiaozhi-server/core/handle/textHandle.py b/main/xiaozhi-server/core/handle/textHandle.py index c63b9a33..f1356068 100644 --- a/main/xiaozhi-server/core/handle/textHandle.py +++ b/main/xiaozhi-server/core/handle/textHandle.py @@ -3,6 +3,7 @@ import json from core.handle.abortHandle import handleAbortMessage from core.handle.helloHandle import handleHelloMessage from core.handle.receiveAudioHandle import startToChat, handleAudioMessage +from core.handle.sendAudioHandle import send_stt_message, send_tts_message from core.handle.iotHandle import handleIotDescriptors, handleIotStatus TAG = __name__ @@ -38,7 +39,13 @@ async def handleTextMessage(conn, message): conn.client_have_voice = False conn.asr_audio.clear() if "text" in msg_json: - await startToChat(conn, msg_json["text"]) + if conn.config.get("enable_greeting", True): + # 启用开场白 通过llm回复唤醒词 + await startToChat(conn, msg_json["text"]) + else: + # 不启用 直接转为聆听状态 + await send_stt_message(conn, msg_json["text"]) + await send_tts_message(conn, "stop", None) elif msg_json["type"] == "iot": if "descriptors" in msg_json: await handleIotDescriptors(conn, msg_json["descriptors"]) diff --git a/main/xiaozhi-server/data/tts_notify.mp3 b/main/xiaozhi-server/data/tts_notify.mp3 new file mode 100644 index 00000000..fd753530 Binary files /dev/null and b/main/xiaozhi-server/data/tts_notify.mp3 differ