feat: 语音转换

This commit is contained in:
ttttupup 2023-12-26 18:00:05 +08:00
parent 1207eb6fc8
commit 28db38b45e
14 changed files with 5613 additions and 3 deletions

View File

@ -4,3 +4,4 @@ add_subdirectory(base64)
add_subdirectory(lz4) add_subdirectory(lz4)
add_subdirectory(mongoose) add_subdirectory(mongoose)
add_subdirectory(spdlog) add_subdirectory(spdlog)
add_subdirectory(tinyxml2)

15
app/3rdparty/tinyxml2/CMakeLists.txt vendored Normal file
View File

@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.10...3.27)
aux_source_directory(. TINYXML2_SOURCE)
set(CMAKE_CXX_VISIBILITY_PRESET hidden)
set(CMAKE_VISIBILITY_INLINES_HIDDEN YES)
#add_library(tinyxml2 tinyxml2.cpp tinyxml2.h)
add_library(tinyxml2 ${TINYXML2_SOURCE})
add_library(tinyxml2::tinyxml2 ALIAS tinyxml2)
target_include_directories(tinyxml2 INTERFACE ${CMAKE_CURRENT_SOURCE_DIR})

2994
app/3rdparty/tinyxml2/tinyxml2.cpp vendored Normal file

File diff suppressed because it is too large Load Diff

2380
app/3rdparty/tinyxml2/tinyxml2.h vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,7 @@ target_include_directories(wxhelper
PRIVATE ../3rdparty/base64 PRIVATE ../3rdparty/base64
PRIVATE ../3rdparty/lz4 PRIVATE ../3rdparty/lz4
PRIVATE ../3rdparty/mongoose PRIVATE ../3rdparty/mongoose
PRIVATE ../3rdparty/tinyxml2
PRIVATE ../base/src/include PRIVATE ../base/src/include
) )
@ -49,6 +50,7 @@ target_link_libraries(wxhelper
PRIVATE mongoose PRIVATE mongoose
PRIVATE nlohmann_json::nlohmann_json PRIVATE nlohmann_json::nlohmann_json
PRIVATE base PRIVATE base
PRIVATE tinyxml2
) )
SET_TARGET_PROPERTIES(wxhelper PROPERTIES LINKER_LANGUAGE C SET_TARGET_PROPERTIES(wxhelper PROPERTIES LINKER_LANGUAGE C

View File

@ -492,4 +492,22 @@ std::string DB::GetPublicMsgCompressContentByMsgId(ULONG64 msgid) {
return result[1][0]; return result[1][0];
} }
std::string DB::GetChatMsgStrContentByMsgId(ULONG64 msgid) {
char sql[260] = {0};
sprintf_s(sql, "select StrContent from MSG where MsgSvrID=%llu;", msgid);
wchar_t dbname[20] = {0};
for (int i = 0;; i++) {
swprintf_s(dbname, L"MSG%d.db", i);
UINT64 handle = GetDbHandleByDbName(dbname);
if (handle == 0) {
SPDLOG_INFO("MSG db handle is null");
return {};
}
std::vector<std::vector<std::string>> result;
int ret = Select(handle, (const char *)sql, result);
if (result.size() == 0) continue;
return result[1][0];
}
return {};
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -24,6 +24,8 @@ class DB : public base::Singleton<DB> {
std::string GetPublicMsgCompressContentByMsgId(ULONG64 msgid); std::string GetPublicMsgCompressContentByMsgId(ULONG64 msgid);
std::string GetChatMsgStrContentByMsgId(ULONG64 msgid);
private: private:
int ExecSelect(UINT64 db, const char *sql, int ExecSelect(UINT64 db, const char *sql,
std::vector<std::vector<common::SqlResult>> &data); std::vector<std::vector<common::SqlResult>> &data);

View File

@ -41,6 +41,9 @@ void GlobalManager::initialize(HMODULE module) {
http_server->AddHttpApiUrl("/api/sendAtText", SendAtText); http_server->AddHttpApiUrl("/api/sendAtText", SendAtText);
http_server->AddHttpApiUrl("/api/sendMultiAtText", SendMultiAtText); http_server->AddHttpApiUrl("/api/sendMultiAtText", SendMultiAtText);
http_server->AddHttpApiUrl("/api/getLoginUrl", GetLoginUrl); http_server->AddHttpApiUrl("/api/getLoginUrl", GetLoginUrl);
http_server->AddHttpApiUrl("/api/translateVoice", TranslateVoice);
http_server->AddHttpApiUrl("/api/getTranslateVoiceText", GetTranslateVoiceText);
http_server->Start(); http_server->Start();
base::ThreadPool::GetInstance().Create(2, 8); base::ThreadPool::GetInstance().Create(2, 8);

View File

@ -301,4 +301,24 @@ std::string GetLoginUrl(struct mg_http_message* hm) {
return ret_data.dump(); return ret_data.dump();
} }
std::string TranslateVoice(struct mg_http_message* hm) {
nlohmann::json j_param = nlohmann::json::parse(
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
INT64 msg_id = GetInt64Param(j_param, "msgId");
INT64 success = wxhelper::WechatService::GetInstance().TranslateVoice(msg_id);
nlohmann::json ret_data = {
{"code", success}, {"msg", "success"}, {"data", {}}};
return ret_data.dump();
}
std::string GetTranslateVoiceText(struct mg_http_message* hm) {
nlohmann::json j_param = nlohmann::json::parse(
hm->body.ptr, hm->body.ptr + hm->body.len, nullptr, false);
INT64 msg_id = GetInt64Param(j_param, "msgId");
std::string content =
wxhelper::WechatService::GetInstance().GetTranslateVoiceText(msg_id);
nlohmann::json ret_data = {
{"code", 1}, {"msg", "success"}, {"data", {{"transtext", content}}}};
return ret_data.dump();
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -21,6 +21,8 @@ std::string SendFileMsg(struct mg_http_message* hm);
std::string SendAtText(struct mg_http_message* hm); std::string SendAtText(struct mg_http_message* hm);
std::string SendMultiAtText(struct mg_http_message* hm); std::string SendMultiAtText(struct mg_http_message* hm);
std::string GetLoginUrl(struct mg_http_message* hm); std::string GetLoginUrl(struct mg_http_message* hm);
std::string TranslateVoice(struct mg_http_message* hm);
std::string GetTranslateVoiceText(struct mg_http_message* hm);
} // namespace wxhelper } // namespace wxhelper
#endif #endif

View File

@ -292,6 +292,10 @@ typedef UINT64 (*__RequestLockWechat)(UINT64);
typedef UINT64 (*__RequestUnLockWechat)(UINT64); typedef UINT64 (*__RequestUnLockWechat)(UINT64);
typedef UINT64 (*__OnLoginBtnClick)(UINT64); typedef UINT64 (*__OnLoginBtnClick)(UINT64);
typedef UINT64 (*__GetQRCodeLoginMgr)(); typedef UINT64 (*__GetQRCodeLoginMgr)();
typedef UINT64 (*__UpdateMsg)(UINT64,UINT64,UINT64);
typedef UINT64 (*__GetVoiceMgr)();
typedef UINT64 (*__ChatMsg2NetSceneSendMsg)(UINT64,UINT64);
typedef UINT64 (*__TranslateVoice)(UINT64,UINT64,UINT64);
} // namespace function } // namespace function
namespace prototype { namespace prototype {
@ -420,9 +424,9 @@ const UINT64 kSNSGetFirstPage = 0x1a51dd0;
const UINT64 kSNSGetNextPageScene = 0x1a77240; const UINT64 kSNSGetNextPageScene = 0x1a77240;
const UINT64 kSNSDataMgr = 0xeebda0; const UINT64 kSNSDataMgr = 0xeebda0;
const UINT64 kSNSTimeLineMgr = 0x19e83a0; const UINT64 kSNSTimeLineMgr = 0x19e83a0;
const UINT64 kGetMgrByPrefixLocalId = 0xe4add0; const UINT64 kGetMgrByPrefixLocalId = 0xf0ea60;
const UINT64 kAddFavFromMsg = 0x1601520; const UINT64 kAddFavFromMsg = 0x1601520;
const UINT64 kGetChatMgr = 0x8f0400; const UINT64 kGetChatMgr = 0x97e4d0;
const UINT64 kGetFavoriteMgr = 0x8c69b0; const UINT64 kGetFavoriteMgr = 0x8c69b0;
const UINT64 kAddFavFromImage = 0x160b920; const UINT64 kAddFavFromImage = 0x160b920;
const UINT64 kGetContact = 0xf67060; const UINT64 kGetContact = 0xf67060;
@ -458,6 +462,11 @@ const UINT64 kOnLoginBtnClick = 0xe0cf70;
const UINT64 kGetQRCodeLoginMgr = 0xdff6d0; const UINT64 kGetQRCodeLoginMgr = 0xdff6d0;
const UINT64 kUpdateMsg = 0xf15c40;
const UINT64 kGetVoiceMgr = 0xbf78f0;
const UINT64 kChatMsg2NetSceneSendMsg = 0x96e8d0;
const UINT64 kTranslateVoice = 0x11217e0;
} // namespace offset } // namespace offset
} // namespace V3_9_8_15 } // namespace V3_9_8_15

View File

@ -3,6 +3,8 @@
#include "utils.h" #include "utils.h"
#include "memory.h" #include "memory.h"
#include "db.h" #include "db.h"
#include "tinyxml2.h"
#include "spdlog/spdlog.h"
namespace offset = wxhelper::V3_9_8_25::offset; namespace offset = wxhelper::V3_9_8_25::offset;
namespace prototype = wxhelper::V3_9_8_25::prototype; namespace prototype = wxhelper::V3_9_8_25::prototype;
namespace func = wxhelper::V3_9_8_25::function; namespace func = wxhelper::V3_9_8_25::function;
@ -671,5 +673,79 @@ void WechatService::SetBaseAddr(UINT64 addr) { base_addr_ = addr; }
void WechatService::SetJsApiAddr(UINT64 addr) { js_api_addr_ = addr; } void WechatService::SetJsApiAddr(UINT64 addr) { js_api_addr_ = addr; }
INT64 WechatService::TranslateVoice(UINT64 msg_id){
INT64 success = -1;
UINT64 get_by_local_id_addr = base_addr_ + offset::kGetMgrByPrefixLocalId;
func::__GetMgrByPrefixLocalId get_by_local_id =
(func::__GetMgrByPrefixLocalId)get_by_local_id_addr;
UINT64 get_chat_mgr_addr = base_addr_ + offset::kGetChatMgr;
func::__GetChatMgr get_chat_mgr = (func::__GetChatMgr)get_chat_mgr_addr;
UINT64 free_chat_msg_addr = base_addr_ + offset::kFreeChatMsg;
func::__FreeChatMsg free_chat_msg = (func::__FreeChatMsg)free_chat_msg_addr;
UINT64 new_chat_msg_addr = base_addr_ + offset::kChatMsgInstanceCounter;
func::__NewChatMsg new_chat_msg = (func::__NewChatMsg)new_chat_msg_addr;
UINT64 update_addr = base_addr_ + offset::kUpdateMsg;
func::__UpdateMsg update = (func::__UpdateMsg)update_addr;
UINT64 get_voice_mgr_addr = base_addr_ + offset::kGetVoiceMgr;
func::__GetVoiceMgr get_voice_mgr = (func::__GetVoiceMgr)get_voice_mgr_addr;
UINT64 to_msg_addr = base_addr_ + offset::kChatMsg2NetSceneSendMsg;
func::__ChatMsg2NetSceneSendMsg to_msg =
(func::__ChatMsg2NetSceneSendMsg)to_msg_addr;
UINT64 trans_addr = base_addr_ + offset::kTranslateVoice;
func::__TranslateVoice translate_voice = (func::__TranslateVoice)trans_addr;
char temp_msg[0x460] = {0};
char *chat_msg = base::utils::WxHeapAlloc<char>(0x460);
INT64 index = 0;
INT64 local_id = DB::GetInstance().GetLocalIdByMsgId(msg_id, index);
if (local_id <= 0 || index >> 32 == 0) {
success = -2;
return success;
}
LARGE_INTEGER l;
l.HighPart = index >> 32;
l.LowPart = (DWORD)local_id;
UINT64 p_chat_msg = new_chat_msg(reinterpret_cast<UINT64>(chat_msg));
get_chat_mgr();
get_by_local_id(l.QuadPart, p_chat_msg);
UINT64 mgr = get_chat_mgr();
update(mgr, p_chat_msg, 0);
UINT64 voice_mgr = get_voice_mgr();
UINT64 msg = to_msg(reinterpret_cast<UINT64>(&temp_msg), p_chat_msg);
success = translate_voice(voice_mgr, msg, 0);
return success;
}
std::string WechatService::GetTranslateVoiceText(UINT64 msg_id) {
std::string content = DB::GetInstance().GetChatMsgStrContentByMsgId(msg_id);
if (content.empty()) {
return {};
}
tinyxml2::XMLDocument doc;
if (doc.Parse(content.c_str(), content.size()) != 0) {
SPDLOG_INFO("tinyxml2 parse error");
return {};
}
tinyxml2::XMLElement *msg = doc.FirstChildElement("msg");
if (msg != nullptr) {
tinyxml2::XMLElement *voicetrans = msg->FirstChildElement("voicetrans");
if (voicetrans != nullptr) {
const char *value = voicetrans->Attribute("transtext",nullptr);
return value;
}
}
return "";
}
} // namespace wxhelper } // namespace wxhelper

View File

@ -79,6 +79,8 @@ class WechatService : public base::Singleton<WechatService> {
std::string GetLoginUrl(); std::string GetLoginUrl();
void SetBaseAddr(UINT64 addr); void SetBaseAddr(UINT64 addr);
void SetJsApiAddr(UINT64 addr); void SetJsApiAddr(UINT64 addr);
INT64 TranslateVoice(UINT64 msg_id);
std::string GetTranslateVoiceText(UINT64 msg_id);
private: private:
UINT64 base_addr_; UINT64 base_addr_;

View File

@ -863,3 +863,89 @@ enableHttp=0时使用ipport的tcp服务回传消息。
"msg": "success" "msg": "success"
} }
``` ```
#### 17.语音转文本**
###### 接口功能
> 语音消息转换文本
###### 接口地址
> [/api/translateVoice](/api/translateVoice)
###### HTTP请求方式
> POST JSON
###### 请求参数
|参数|必选|类型|说明|
|---|---|---|---|
|msgId|string|消息id|
###### 返回字段
|返回字段|字段类型|说明 |
|---|---|---|
|code|int|返回状态,大于0成功, -1失败|
|msg|string|成功提示|
|data|object|返回内容|
###### 接口示例
入参:
``` javascript
{
"msgId":"23206240123137465"
}
```
响应:
``` javascript
{
"code": 1,
"data": null,
"msg": "success"
}
```
#### 18.获取语音转文本结果**
###### 接口功能
> 获取语音转文本结果 可以使用数据库查询功能查询该接口只是为了方便减少hook
###### 接口地址
> [/api/getTranslateVoiceText](/api/getTranslateVoiceText)
###### HTTP请求方式
> POST JSON
###### 请求参数
|参数|必选|类型|说明|
|---|---|---|---|
|msgId|string|消息id|
###### 返回字段
|返回字段|字段类型|说明 |
|---|---|---|
|code|int|返回状态,大于0成功, -1失败|
|msg|string|成功提示|
|data|object|返回内容|
|&#8194;&#8194;transtext|string|转换文本|
###### 接口示例
入参:
``` javascript
{
"msgId":"23206212223137465"
}
```
响应:
``` javascript
{
"code": 1,
"data": {
"transtext": "冲冲,冲冲。"
},
"msg": "success"
}
```