From e53828697ee97c261fd964a38632f324a8ed599e Mon Sep 17 00:00:00 2001 From: zhaohe Date: Tue, 12 Sep 2023 19:23:01 +0800 Subject: [PATCH] update aidui_service --- src/iflytop/components/aiui_ws/aiui_service.cpp | 15 ++++++++------- src/iflytop/components/aiui_ws/aiui_service.hpp | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/iflytop/components/aiui_ws/aiui_service.cpp b/src/iflytop/components/aiui_ws/aiui_service.cpp index 41d7e54..6364789 100644 --- a/src/iflytop/components/aiui_ws/aiui_service.cpp +++ b/src/iflytop/components/aiui_ws/aiui_service.cpp @@ -30,11 +30,13 @@ void AiuiService::dumpRxResult(json rxjson) { logger->info("rx aiui data: {}", rxjson.dump()); } } -void AiuiService::onmessage(const ix::WebSocketMessagePtr &msg) { +void AiuiService::onmessage(string sessionid, const ix::WebSocketMessagePtr &msg) { if (msg->type == ix::WebSocketMessageType::Message) { if (!msg->binary) { try { json rxjson = json::parse(msg->str); + + rxjson["iflytop"]["sessionid"] = sessionid; onMessage(rxjson); } catch (const std::exception &e) { logger->error("AiuiService::call_aiui_message_cb error: {}", e.what()); @@ -103,12 +105,12 @@ int AiuiService::initialize(string appid, string key, string param) { m_param = param; return 0; } -int AiuiService::aiuiInit() { +int AiuiService::aiuiInit(string session_id) { lock_guard lock(lock_); - return aiuiInit(m_appid, m_key, m_param); + return aiuiInit(m_appid, m_key, m_param, session_id); } -int AiuiService::aiuiInit(string appid, string key, string param) { +int AiuiService::aiuiInit(string appid, string key, string param, string sessionid) { lock_guard lock(lock_); if (m_webSocket) { @@ -119,11 +121,10 @@ int AiuiService::aiuiInit(string appid, string key, string param) { string time_str = create_time_str(); string paramAfterBase64 = base64_encode((const char *)param.data(), param.size()); string checksum = encode_sh256(fmt::format("{}{}{}", key, time_str, paramAfterBase64)); - string url = fmt::format("ws://wsapi.xfyun.cn:80/v1/aiui?appid={}&checksum={}&curtime={}¶m={}&signtype=sha256", - appid, checksum, time_str, paramAfterBase64); + string url = fmt::format("ws://wsapi.xfyun.cn:80/v1/aiui?appid={}&checksum={}&curtime={}¶m={}&signtype=sha256", appid, checksum, time_str, paramAfterBase64); m_webSocket.reset(new ix::WebSocket()); m_webSocket->setUrl(url); - m_webSocket->setOnMessageCallback([this](const ix::WebSocketMessagePtr &msg) { onmessage(msg); }); + m_webSocket->setOnMessageCallback([this, sessionid](const ix::WebSocketMessagePtr &msg) { onmessage(sessionid, msg); }); ix::WebSocketHttpHeaders headers; headers["Origin"] = "https://wsapi.xfyun.cn"; m_webSocket->setExtraHeaders(headers); diff --git a/src/iflytop/components/aiui_ws/aiui_service.hpp b/src/iflytop/components/aiui_ws/aiui_service.hpp index fbf38a9..4dd3bec 100644 --- a/src/iflytop/components/aiui_ws/aiui_service.hpp +++ b/src/iflytop/components/aiui_ws/aiui_service.hpp @@ -70,7 +70,7 @@ class AiuiService : public enable_shared_from_this { * https://aiui-doc.xf-yun.com/project-1/doc-17/ */ int initialize(string appid, string key, string param); - int aiuiInit(); + int aiuiInit(string session_id); int aiuiWrite(const char *audio, int len); int aiuiFinished(); void aiuiDestroy(); @@ -93,10 +93,10 @@ class AiuiService : public enable_shared_from_this { void dumpRxResult(json rxjson); private: - int aiuiInit(string appid, string key, string param); + int aiuiInit(string appid, string key, string param, string sessionid); string storageRxTTS(); string create_time_str(); string encode_sh256(string str); - void onmessage(const ix::WebSocketMessagePtr &msg); + void onmessage(string sessionid, const ix::WebSocketMessagePtr &msg); }; } // namespace iflytop