Просмотр исходного кода

通话结束时添加close消息

baiwenju лет назад: 2
Родитель
Сommit
99dc08023d

+ 55 - 1
AsrService/AsrService.cpp

@@ -8,6 +8,58 @@
8 8
 #include "CRedis.h"
9 9
 #include "Util.h"
10 10
 #include <fstream>
11
+#include "dump.h"
12
+
13
+void writeLog(std::string strContent) {
14
+	std::ofstream of;
15
+	of.open("./logs/bp.txt", std::ios_base::app);
16
+	if (of.is_open()) {
17
+		of << strContent << std::endl;
18
+		of.flush();
19
+		of.close();
20
+	}
21
+}
22
+
23
+bool Ctrlhandler(DWORD fdwctrltype)
24
+{
25
+	LOG_ERROR("关闭代码[%d]", fdwctrltype);
26
+	//Sleep(1000);
27
+	switch (fdwctrltype)
28
+	{
29
+		// handle the ctrl-c signal.
30
+	case CTRL_C_EVENT:
31
+		LOG_ERROR("ctrl-c event\n\n");
32
+		Sleep(200);
33
+		return(true);
34
+		// ctrl-close: confirm that the user wants to exit.
35
+	case CTRL_CLOSE_EVENT:
36
+		//Close_Exit = true;
37
+		LOG_ERROR("ctrl-close event\n\n");
38
+		writeLog("ctrl-close event\n\n");
39
+		Sleep(2000);
40
+		return(true);
41
+		// pass other signals to the next handler.
42
+	case CTRL_BREAK_EVENT:
43
+		//Close_Exit = true;
44
+		LOG_ERROR("ctrl-break event\n\n");
45
+		Sleep(200);
46
+		return false;
47
+	case CTRL_LOGOFF_EVENT:
48
+		//Close_Exit = true;
49
+		LOG_ERROR("ctrl-logoff event\n\n");
50
+		Sleep(200);
51
+		return false;
52
+	case CTRL_SHUTDOWN_EVENT:
53
+	//	Close_Exit = true;
54
+		LOG_ERROR("ctrl-shutdown event\n\n");
55
+		Sleep(200);
56
+		return false;
57
+	default:
58
+		LOG_ERROR("未知");
59
+		Sleep(200);
60
+		return false;
61
+	}
62
+}
11 63
 
12 64
 // IsAlreadyRunning - 是否已经运行
13 65
 BOOL IsAlreadyRunning()
@@ -41,6 +93,8 @@ int main()
41 93
 		system("pause");
42 94
 		return 0;
43 95
 	}
96
+	// 加入崩溃dump文件功能
97
+	SetUnhandledExceptionFilter(ExceptionFilter);
44 98
 
45 99
 	if (MYLog::instance()->Init() != 0)
46 100
 	{
@@ -56,7 +110,7 @@ int main()
56 110
 		return 0;
57 111
 	}
58 112
 	LOG_INFO("FS配置文件加载成功");
59
-
113
+	SetConsoleCtrlHandler((PHANDLER_ROUTINE)Ctrlhandler, true);
60 114
 	if (!CRedis::GetInstance()->connect())
61 115
 	{
62 116
 		LOG_ERROR("Redis连接失败");

+ 1 - 0
AsrService/AsrService.vcxproj

@@ -174,6 +174,7 @@
174 174
     <ClInclude Include="..\public\tinyxml\tinyxml.h" />
175 175
     <ClInclude Include="Config.h" />
176 176
     <ClInclude Include="CRedis.h" />
177
+    <ClInclude Include="dump.h" />
177 178
     <ClInclude Include="EslGateway.h" />
178 179
     <ClInclude Include="Log.h" />
179 180
     <ClInclude Include="pubdef.h" />

+ 6 - 0
AsrService/AsrService.vcxproj.filters

@@ -34,6 +34,9 @@
34 34
     <Filter Include="tinyxml">
35 35
       <UniqueIdentifier>{73c07811-985c-494a-b8b0-b6ff9ae5a583}</UniqueIdentifier>
36 36
     </Filter>
37
+    <Filter Include="dump">
38
+      <UniqueIdentifier>{067043f8-d9af-48d6-a3cd-365f7fc9e54c}</UniqueIdentifier>
39
+    </Filter>
37 40
   </ItemGroup>
38 41
   <ItemGroup>
39 42
     <ClCompile Include="AsrService.cpp">
@@ -101,5 +104,8 @@
101 104
     <ClInclude Include="pubdef.h">
102 105
       <Filter>头文件</Filter>
103 106
     </ClInclude>
107
+    <ClInclude Include="dump.h">
108
+      <Filter>dump</Filter>
109
+    </ClInclude>
104 110
   </ItemGroup>
105 111
 </Project>

+ 0 - 112
AsrService/CRedis - 副本 (2).cpp

@@ -1,112 +0,0 @@
1
-#include "CRedis.h"
2
-#include <string.h>
3
-#include "Config.h"
4
-
5
-//#define LOG_ERROR         printf 
6
-//#define LOG_INFO          printf
7
-//#define LOG_DEBUG         printf
8
-
9
-#ifdef WIN32
10
-#define NO_QFORKIMPL //这一行必须加才能正常使用
11
-#include "hiredis\msvs\win32_interop\win32_fixes.h"
12
-#pragma comment(lib,"hiredis.lib")
13
-#pragma comment(lib,"win32_interop.lib")
14
-#pragma comment(lib,"redis++_static.lib")
15
-#endif // WIN32
16
-
17
-CRedis::CRedis()
18
-{
19
-	 m_pHost = nullptr;
20
-	 m_port = 6379;
21
-	 m_pPwd = nullptr;
22
-}
23
-
24
-CRedis::~CRedis()
25
-{
26
-	
27
-}
28
-
29
-bool CRedis::connect()
30
-{
31
-	auto cfg = CConfig::GetInstance();
32
-	return connect(cfg->redisIp().c_str(),cfg->redisPort(),cfg->redisPwd().c_str());
33
-}
34
-
35
-bool CRedis::connect(const char * host, int port, const char * password)
36
-{
37
-	try
38
-	{
39
-		auto cfg = CConfig::GetInstance();
40
-		LOG_INFO("Redis连接[%s][%d][%s]", cfg->redisIp().c_str(), cfg->redisPort(), cfg->redisPwd().c_str());
41
-		
42
-		// Set a master node's host & port.
43
-		ConnectionOptions connection_options;
44
-		connection_options.host = host;  // Required.
45
-		connection_options.port = port; // Optional. The default port is 6379.
46
-		connection_options.password = password; // Optional. No password by default.
47
-
48
-		ConnectionPoolOptions pool_options;
49
-		pool_options.size = 3;
50
-
51
-		// Automatically get other nodes' info,
52
-		// and connect to every master node with a single connection.
53
-		//RedisCluster cluster1(connection_options);
54
-		m_pRedisCluster = std::make_unique<RedisCluster>(connection_options, pool_options);
55
-	}
56
-	catch (const std::exception& e)
57
-	{
58
-		LOG_ERROR_S(e.what());
59
-	}
60
-
61
-	
62
-	return true;
63
-}
64
-
65
-bool CRedis::set(const char * key, const char * value)
66
-{
67
-	return false;
68
-}
69
-
70
-bool CRedis::set(const char * key, const char * value, int second)
71
-{
72
-	return false;
73
-}
74
-
75
-void CRedis::push(const char * key, const char * values)
76
-{
77
-	try
78
-	{
79
-		m_pRedisCluster->publish(key, values);
80
-		//LOG_WARN("推送 %ld", m_pRedisCluster->publish(key, values));
81
-	}
82
-	catch (const std::exception& e)
83
-	{
84
-		LOG_ERROR_S(e.what());
85
-	}
86
-}
87
-
88
-void CRedis::push(const char * key, std::list<const char*> &values)
89
-{
90
-	while (!values.empty())
91
-	{
92
-		
93
-		values.pop_front();
94
-	}
95
-	
96
-}
97
-
98
-void CRedis::pull(const char * key, std::list<const char*>& values)
99
-{
100
-	
101
-}
102
-
103
-const char * CRedis::get(const char * key)
104
-{
105
-	return nullptr;
106
-}
107
-
108
-void CRedis::__delKey(const char * key)
109
-{
110
-}
111
-
112
-std::shared_ptr<CRedis> CRedis::pInstance(new CRedis);

+ 0 - 46
AsrService/CRedis - 副本 (2).h

@@ -1,46 +0,0 @@
1
-#pragma once
2
-
3
-
4
-#include <list>
5
-#include <mutex>
6
-#include <memory>
7
-#include "Log.h"
8
-#include <sw/redis++/redis++.h>
9
-#include <sw/redis++/sentinel.h>
10
-#include <sw/redis++/connection.h>
11
-#include <sw/redis++/connection_pool.h>
12
-using namespace sw::redis;
13
-using namespace std::chrono;
14
-
15
-class CRedis
16
-{
17
-private:
18
-	CRedis();
19
-	CRedis(const CRedis&) = default;
20
-	CRedis& operator=(const CRedis&) = default;
21
-public:
22
-	~CRedis();
23
-public:
24
-	bool connect();
25
-	bool connect(const char* host, int port, const char* password);
26
-	bool set(const char* key, const char* value);
27
-	bool set(const char* key, const char* value, int second);
28
-	void push(const char* key, const char* values);
29
-	void push(const char* key, std::list<const char*> &values);
30
-	void pull(const char* key, std::list<const char*> &values);
31
-	const char* get(const char* key);
32
-
33
-	static std::shared_ptr<CRedis> GetInstance() { return pInstance; }
34
-
35
-private:
36
-	void __delKey(const char* key);
37
-
38
-private:
39
-	std::unique_ptr<RedisCluster> m_pRedisCluster;
40
-	std::unique_ptr<char[]> m_pHost;
41
-	int32_t m_port;
42
-	std::unique_ptr<char[]> m_pPwd;
43
-
44
-	static std::shared_ptr<CRedis> pInstance;
45
-};
46
-

+ 2 - 2
AsrService/CRedis.cpp

@@ -26,8 +26,8 @@ CRedis::CRedis()
26 26
 
27 27
 CRedis::~CRedis()
28 28
 {
29
-	if (this->_reply != nullptr)
30
-		freeReplyObject(this->_reply);
29
+	/*if (this->_reply != nullptr)
30
+		freeReplyObject(this->_reply);*/
31 31
 	if (this->_connect != nullptr)
32 32
 		redisFree(this->_connect);
33 33
 	this->_connect = nullptr;

+ 42 - 2
AsrService/EslGateway.cpp

@@ -323,7 +323,6 @@ void CEslGateway::__detectSpeech(esl_event_t * pEvent)
323 323
 			{
324 324
 				LOG_ERROR("utf转ansi失败,失败信息:%s;Redis推送内容\n%s", e.what(), parseResult.c_str());
325 325
 			}
326
-			
327 326
 		}
328 327
 		else
329 328
 		{
@@ -334,8 +333,49 @@ void CEslGateway::__detectSpeech(esl_event_t * pEvent)
334 333
 	{
335 334
 		{
336 335
 			auto it = m_chanAsrInfo.find(ChanId);
337
-			if (it != m_chanAsrInfo.end())
336
+			if (it != m_chanAsrInfo.end()) {
337
+				// 组redis包
338
+				std::string chanAsrInfo;
339
+		
340
+				chanAsrInfo = it->second;
338 341
 				m_chanAsrInfo.erase(it);
342
+
343
+				AsrInfo asrInfo(chanAsrInfo);
344
+				
345
+				// 2023-08-14 停止识别时发送通话结束标识
346
+				asrInfo.state = "end";
347
+				asrInfo.transSentenceText = "";
348
+				asrInfo.sentenceBeginTime = 0;
349
+				asrInfo.transSentenceTime = 0;
350
+				asrInfo.createTime = timestamp; // GetUnixTime();   // 当前13位时间戳
351
+
352
+				auto it = m_CallIdSign.find(asrInfo.callId);
353
+				if (it != m_CallIdSign.end()) asrInfo.transSentenceIndex = it->second->getTansSentenceIndex(asrInfo.callId, ChanId);
354
+				else
355
+				{
356
+					std::shared_ptr<CallIdSign> pCallIdSign = std::make_shared<CallIdSign>();
357
+					asrInfo.transSentenceIndex = pCallIdSign->getTansSentenceIndex(asrInfo.callId, ChanId);
358
+					m_CallIdSign[asrInfo.callId] = pCallIdSign;
359
+				}
360
+				std::string parseResult = "";
361
+				asrInfo >> parseResult;
362
+
363
+				if (asrInfo.vocDirect == "Agent") {
364
+					__pushRedis(parseResult.c_str()); // 推送到redis
365
+
366
+					try
367
+					{
368
+						LOG_INFO("Redis推送内容\n%s", utf8_to_ansi(parseResult).c_str());
369
+					}
370
+					catch (const std::exception&e)
371
+					{
372
+						LOG_ERROR("utf转ansi失败,失败信息:%s;Redis推送内容\n%s", e.what(), parseResult.c_str());
373
+					}
374
+				}
375
+				else {
376
+					LOG_INFO("非坐席挂断不推送-end\n%s", parseResult.c_str());
377
+				}
378
+			}
339 379
 		}
340 380
 		{
341 381
 			auto it = m_beginTime.find(ChanId);

+ 2 - 2
AsrService/Release/AsrService.log

@@ -1,8 +1,8 @@
1 1
   EslGateway.cpp
2 2
     正在创建库 G:\git\AsrService\Release\AsrService.lib 和对象 G:\git\AsrService\Release\AsrService.exp
3 3
   正在生成代码
4
-  33 of 3105 functions ( 1.1%) were compiled, the rest were copied from previous compilation.
4
+  1 of 3115 functions (<0.1%) were compiled, the rest were copied from previous compilation.
5 5
     0 functions were new in current compilation
6
-    12 functions had inline decision re-evaluated but remain unchanged
6
+    1 functions had inline decision re-evaluated but remain unchanged
7 7
   已完成代码的生成
8 8
   AsrService.vcxproj -> G:\git\AsrService\Release\AsrService.exe

BIN
AsrService/Release/AsrService.obj


BIN
AsrService/Release/AsrService.tlog/AsrService.write.1u.tlog


BIN
AsrService/Release/AsrService.tlog/CL.command.1.tlog


BIN
AsrService/Release/AsrService.tlog/CL.read.1.tlog


BIN
AsrService/Release/AsrService.tlog/CL.write.1.tlog


BIN
AsrService/Release/AsrService.tlog/link.read.1.tlog


BIN
AsrService/Release/CRedis.obj


BIN
AsrService/Release/EslGateway.obj


BIN
AsrService/Release/vc141.pdb


+ 68 - 0
AsrService/dump.h

@@ -0,0 +1,68 @@
1
+#include "Windows.h"
2
+#include "DbgHelp.h"
3
+#include <cstdlib>
4
+#include <cstdio>
5
+
6
+int GenerateMiniDump(PEXCEPTION_POINTERS pExceptionPointers)
7
+{
8
+	// 定义函数指针
9
+	typedef BOOL(WINAPI * MiniDumpWriteDumpT)(
10
+		HANDLE,
11
+		DWORD,
12
+		HANDLE,
13
+		MINIDUMP_TYPE,
14
+		PMINIDUMP_EXCEPTION_INFORMATION,
15
+		PMINIDUMP_USER_STREAM_INFORMATION,
16
+		PMINIDUMP_CALLBACK_INFORMATION
17
+		);
18
+	// 从 "DbgHelp.dll" 库中获取 "MiniDumpWriteDump" 函数
19
+	MiniDumpWriteDumpT pfnMiniDumpWriteDump = NULL;
20
+	HMODULE hDbgHelp = LoadLibrary(("DbgHelp.dll"));
21
+	if (NULL == hDbgHelp)
22
+	{
23
+		return EXCEPTION_CONTINUE_EXECUTION;
24
+	}
25
+	pfnMiniDumpWriteDump = (MiniDumpWriteDumpT)GetProcAddress(hDbgHelp, "MiniDumpWriteDump");
26
+
27
+	if (NULL == pfnMiniDumpWriteDump)
28
+	{
29
+		FreeLibrary(hDbgHelp);
30
+		return EXCEPTION_CONTINUE_EXECUTION;
31
+	}
32
+	// 创建 dmp 文件件
33
+	CHAR szFileName[MAX_PATH] = { 0 };
34
+	const CHAR* szVersion = ("DumpDemo_v1.0");
35
+	SYSTEMTIME stLocalTime;
36
+	GetLocalTime(&stLocalTime);
37
+	sprintf_s(szFileName, "%s-%04d%02d%02d-%02d%02d%02d.dmp",
38
+		szVersion, stLocalTime.wYear, stLocalTime.wMonth, stLocalTime.wDay,
39
+		stLocalTime.wHour, stLocalTime.wMinute, stLocalTime.wSecond);
40
+	HANDLE hDumpFile = CreateFile(szFileName, GENERIC_READ | GENERIC_WRITE,
41
+		FILE_SHARE_WRITE | FILE_SHARE_READ, 0, CREATE_ALWAYS, 0, 0);
42
+	if (INVALID_HANDLE_VALUE == hDumpFile)
43
+	{
44
+		FreeLibrary(hDbgHelp);
45
+		return EXCEPTION_CONTINUE_EXECUTION;
46
+	}
47
+	// 写入 dmp 文件
48
+	MINIDUMP_EXCEPTION_INFORMATION expParam;
49
+	expParam.ThreadId = GetCurrentThreadId();
50
+	expParam.ExceptionPointers = pExceptionPointers;
51
+	expParam.ClientPointers = FALSE;
52
+	pfnMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
53
+		hDumpFile, MiniDumpWithDataSegs, (pExceptionPointers ? &expParam : NULL), NULL, NULL);
54
+	// 释放文件
55
+	CloseHandle(hDumpFile);
56
+	FreeLibrary(hDbgHelp);
57
+	return EXCEPTION_EXECUTE_HANDLER;
58
+}
59
+
60
+LONG WINAPI ExceptionFilter(LPEXCEPTION_POINTERS lpExceptionInfo)
61
+{
62
+	// 这里做一些异常的过滤或提示
63
+	if (IsDebuggerPresent())
64
+	{
65
+		return EXCEPTION_CONTINUE_SEARCH;
66
+	}
67
+	return GenerateMiniDump(lpExceptionInfo);
68
+}

BIN
Release/AsrService.exe


BIN
Release/AsrService.iobj


BIN
Release/AsrService.ipdb


BIN
Release/AsrService.pdb