mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-22 23:23:55 +08:00
* Update util.py解决返回元组报错 (#103) 解决返回元组报错 * 增加播放本地音乐功能 (#105) * Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. On branch Music-playback Your branch is up to date with 'origin/Music-playback'. Changes to be committed: modified: core/handle/audioHandle.py new file: "music/\346\234\210\344\272\256\344\273\243\350\241\250\346\210\221\347\232\204\345\277\203_\351\202\223\344\270\275\345\220\233.mp3" new file: "music/\350\270\217\345\261\261\346\262\263.mp3" * Please enter the commit message for your changes. Lines starting with '#' will be ignored, and an empty message aborts the commit. On branch Music-playback Your branch is up to date with 'origin/Music-playback'. Changes to be committed: modified: config.yaml modified: core/connection.py modified: core/handle/abortHandle.py modified: core/handle/audioHandle.py new file: core/handle/musicHandler.py modified: core/handle/textHandle.py modified: core/websocket_server.py new file: "music/\344\270\200\345\277\265\345\215\203\345\271\264_\345\233\275\351\243\216\347\211\210.mp3" new file: "music/\344\270\255\347\247\213\346\234\210.mp3" deleted: "music/\346\234\210\344\272\256\344\273\243\350\241\250\346\210\221\347\232\204\345\277\203_\351\202\223\344\270\275\345\220\233.mp3" deleted: "music/\350\270\217\345\261\261\346\262\263.mp3" * 增加播放本地音乐功能 * 增加播放本地音乐功能 * 让音乐配置变的优雅 On branch Music-playback Your branch is up to date with 'origin/Music-playback'. Changes to be committed: modified: config.yaml modified: core/handle/musicHandler.py renamed: "music/\344\270\200\345\277\265\345\215\203\345\271\264_\345\233\275\351\243\216\347\211\210.mp3" -> "music/mp3/\344\270\200\345\277\265\345\215\203\345\271\264_\345\233\275\351\243\216\347\211\210.mp3" renamed: "music/\344\270\255\347\247\213\346\234\210.mp3" -> "music/mp3/\344\270\255\347\247\213\346\234\210.mp3" renamed: "music/\345\273\211\346\263\242\350\200\201\347\237\243\357\274\214\345\260\232\350\203\275\351\245\255\345\220\246.mp3" -> "music/mp3/\345\273\211\346\263\242\350\200\201\347\237\243\357\274\214\345\260\232\350\203\275\351\245\255\345\220\246.mp3" new file: music/music_config.yaml --------- Co-authored-by: 欣南科技 <huangrongzhuang@xin-nan.com> * update:优化代码 * update:流控调试 * update:优化音乐播放 * update:优化音乐配置初始化 --------- Co-authored-by: linqingping <linqingping@users.noreply.github.com> Co-authored-by: Chris <119588753+Chris-websketch@users.noreply.github.com> Co-authored-by: hrz <1710360675@qq.com>
45 lines
1.8 KiB
Python
45 lines
1.8 KiB
Python
from config.logger import setup_logging
|
|
import json
|
|
from core.handle.abortHandle import handleAbortMessage
|
|
from core.handle.helloHandle import handleHelloMessage
|
|
from core.handle.receiveAudioHandle import startToChat
|
|
from core.handle.iotHandle import handleIotDescriptors
|
|
|
|
TAG = __name__
|
|
logger = setup_logging()
|
|
|
|
|
|
async def handleTextMessage(conn, message):
|
|
"""处理文本消息"""
|
|
logger.bind(tag=TAG).info(f"收到文本消息:{message}")
|
|
try:
|
|
msg_json = json.loads(message)
|
|
if isinstance(msg_json, int):
|
|
await conn.websocket.send(message)
|
|
return
|
|
if msg_json["type"] == "hello":
|
|
await handleHelloMessage(conn)
|
|
elif msg_json["type"] == "abort":
|
|
await handleAbortMessage(conn)
|
|
elif msg_json["type"] == "listen":
|
|
if "mode" in msg_json:
|
|
conn.client_listen_mode = msg_json["mode"]
|
|
logger.bind(tag=TAG).debug(f"客户端拾音模式:{conn.client_listen_mode}")
|
|
if msg_json["state"] == "start":
|
|
conn.client_have_voice = True
|
|
conn.client_voice_stop = False
|
|
elif msg_json["state"] == "stop":
|
|
conn.client_have_voice = True
|
|
conn.client_voice_stop = True
|
|
elif msg_json["state"] == "detect":
|
|
conn.asr_server_receive = False
|
|
conn.client_have_voice = False
|
|
conn.asr_audio.clear()
|
|
if "text" in msg_json:
|
|
await startToChat(conn, msg_json["text"])
|
|
elif msg_json["type"] == "iot":
|
|
if "descriptors" in msg_json:
|
|
await handleIotDescriptors(conn, msg_json["descriptors"])
|
|
except json.JSONDecodeError:
|
|
await conn.websocket.send(message)
|