|
|
@ -217,7 +217,7 @@ async def human(request):
|
|
|
|
nerfreals[sessionid].flush_talk()
|
|
|
|
nerfreals[sessionid].flush_talk()
|
|
|
|
|
|
|
|
|
|
|
|
if params['type'] == 'echo':
|
|
|
|
if params['type'] == 'echo':
|
|
|
|
nerfreals[sessionid].liv_speaking = True
|
|
|
|
nerfreals[sessionid].set_speaking_state(True)
|
|
|
|
nerfreals[sessionid].put_msg_txt(params['text'])
|
|
|
|
nerfreals[sessionid].put_msg_txt(params['text'])
|
|
|
|
|
|
|
|
|
|
|
|
elif params['type'] == 'chat':
|
|
|
|
elif params['type'] == 'chat':
|
|
|
@ -288,6 +288,61 @@ async def humanaudio(request):
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def set_live_room_control_mode(request):
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
params = await request.json()
|
|
|
|
|
|
|
|
current_control_mode = params.get('current_control_mode', 0)
|
|
|
|
|
|
|
|
sessionid = params.get('sessionid', 0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 检查 sessionid 是否存在
|
|
|
|
|
|
|
|
if sessionid not in nerfreals:
|
|
|
|
|
|
|
|
return web.Response(
|
|
|
|
|
|
|
|
content_type="application/json",
|
|
|
|
|
|
|
|
text=json.dumps({"code": 404, "msg": f"Session {sessionid} not found"})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 如果当前为手动接管模式
|
|
|
|
|
|
|
|
if current_control_mode == 0: # 手动接管
|
|
|
|
|
|
|
|
# 1. 暂停当前讲话
|
|
|
|
|
|
|
|
nerfreals[sessionid].flush_talk() # 先暂停当前语音合成
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2. 设置手动接管模式
|
|
|
|
|
|
|
|
nerfreals[sessionid].manual_control_mode = True
|
|
|
|
|
|
|
|
logger.info(f"Live room control mode set to manual for session {sessionid}. Chat will be stopped.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 3. 将 liv_speaking 设置为 True
|
|
|
|
|
|
|
|
nerfreals[sessionid].liv_speaking = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return web.Response(
|
|
|
|
|
|
|
|
content_type="application/json",
|
|
|
|
|
|
|
|
text=json.dumps({"code": 200, "msg": "Live room control mode set to manual"})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 如果切换到 AI 接管模式
|
|
|
|
|
|
|
|
elif current_control_mode == 1: # AI 接管
|
|
|
|
|
|
|
|
# 1. 设置为 AI 接管
|
|
|
|
|
|
|
|
nerfreals[sessionid].manual_control_mode = False # 设置为 AI 接管
|
|
|
|
|
|
|
|
logger.info(f"Live room control mode set to AI for session {sessionid}. Chat can resume sending messages.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# 2. 告知chat服务可以继续讲话
|
|
|
|
|
|
|
|
nerfreals[sessionid].set_speaking_state(False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return web.Response(
|
|
|
|
|
|
|
|
content_type="application/json",
|
|
|
|
|
|
|
|
text=json.dumps({"code": 200, "msg": "Live room control mode set to AI"})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
return web.Response(
|
|
|
|
|
|
|
|
content_type="application/json",
|
|
|
|
|
|
|
|
text=json.dumps({"code": 400, "msg": "Invalid control mode"})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
logger.exception('Error in set_live_room_control_mode:')
|
|
|
|
|
|
|
|
return web.Response(
|
|
|
|
|
|
|
|
content_type="application/json",
|
|
|
|
|
|
|
|
text=json.dumps({"code": 500, "msg": str(e)})
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
async def set_audiotype(request):
|
|
|
|
async def set_audiotype(request):
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
params = await request.json()
|
|
|
|
params = await request.json()
|
|
|
@ -519,6 +574,8 @@ if __name__ == '__main__':
|
|
|
|
appasync.router.add_post("/record", record)
|
|
|
|
appasync.router.add_post("/record", record)
|
|
|
|
appasync.router.add_post("/interrupt_talk", interrupt_talk)
|
|
|
|
appasync.router.add_post("/interrupt_talk", interrupt_talk)
|
|
|
|
appasync.router.add_post("/is_speaking", is_speaking)
|
|
|
|
appasync.router.add_post("/is_speaking", is_speaking)
|
|
|
|
|
|
|
|
appasync.router.add_post("/set_live_room_control_mode", set_live_room_control_mode)
|
|
|
|
|
|
|
|
appasync.router.add_post("/live_speaking_status", live_speaking_status)
|
|
|
|
appasync.router.add_static('/', path='web')
|
|
|
|
appasync.router.add_static('/', path='web')
|
|
|
|
|
|
|
|
|
|
|
|
# Configure default CORS settings.
|
|
|
|
# Configure default CORS settings.
|
|
|
|