Browse Source

讯飞asr测试,debug

Davidliu 1 month ago
parent
commit
d199d4a2d2
2 changed files with 40 additions and 40 deletions
  1. 32 32
      src/core/callcenter/config.py
  2. 8 8
      src/core/voip/asr.py

+ 32 - 32
src/core/callcenter/config.py

@@ -21,35 +21,35 @@ class BaseConfig(object):
     SQLALCHEMY_ECHO = False  # Optional: Log SQL queries
 
 
-# dictConfig({
-#         "version": 1,
-#         "disable_existing_loggers": True,  # 不覆盖默认配置
-#         "formatters": {  # 日志输出样式
-#             "default": {
-#                 "format": "%(asctime)s - %(module)s.%(lineno)d - %(levelname)s - %(threadName)s: %(message)s"
-#             }
-#         },
-#         "handlers": {
-#             "console": {
-#                 "class": "logging.StreamHandler",  # 控制台输出
-#                 "level": "DEBUG",
-#                 "formatter": "default",
-#             },
-#             "log_file": {
-#                 "class": "logging.handlers.TimedRotatingFileHandler",  # 按时间切分日志
-#                 "level": "DEBUG",
-#                 "formatter": "default",   # 日志输出样式对应formatters
-#                 "filename": "./logs/flask.log",  # 指定log文件目录
-#                 "when": "midnight",        # 按天切分,午夜时分创建新文件
-#                 "interval": 1,             # 间隔1天
-#                 "backupCount": 10,         # 保留10天的日志文件
-#                 "encoding": "utf8",        # 文件编码
-#             },
-#
-#         },
-#         "root": {
-#             "level": "DEBUG",  # # handler中的level会覆盖掉这里的level
-#             "handlers": ["console", "log_file"],
-#         },
-#     }
-# )
+dictConfig({
+        "version": 1,
+        "disable_existing_loggers": True,  # 不覆盖默认配置
+        "formatters": {  # 日志输出样式
+            "default": {
+                "format": "%(asctime)s - %(module)s.%(lineno)d - %(levelname)s - %(threadName)s: %(message)s"
+            }
+        },
+        "handlers": {
+            "console": {
+                "class": "logging.StreamHandler",  # 控制台输出
+                "level": "DEBUG",
+                "formatter": "default",
+            },
+            # "log_file": {
+            #     "class": "logging.handlers.TimedRotatingFileHandler",  # 按时间切分日志
+            #     "level": "DEBUG",
+            #     "formatter": "default",   # 日志输出样式对应formatters
+            #     "filename": "./logs/flask.log",  # 指定log文件目录
+            #     "when": "midnight",        # 按天切分,午夜时分创建新文件
+            #     "interval": 1,             # 间隔1天
+            #     "backupCount": 10,         # 保留10天的日志文件
+            #     "encoding": "utf8",        # 文件编码
+            # },
+
+        },
+        "root": {
+            "level": "DEBUG",  # # handler中的level会覆盖掉这里的level
+            "handlers": ["console"],
+        },
+    }
+)

+ 8 - 8
src/core/voip/asr.py

@@ -206,7 +206,7 @@ class XfAsr:
         self.logger = logger
         self.message_receiver = message_receiver
         self.ws = self.new_connection()
-        self.logger.info(f"xunfei.Asr: ws.connected:{self.ws.connected}")
+        self.logger.info(f"xunfei.Asr: call_id: {tid}, ws.connected:{self.ws.connected}")
         self.trecv = threading.Thread(target=self.recv)
 
     def new_connection(self, base_url = "ws://rtasr.xfyun.cn/v1/ws", app_id = "1ec1097b", api_key = "60b7d2d8d172b065b1c3e723e5ba0696"):
@@ -243,7 +243,7 @@ class XfAsr:
                 break
             except Exception as e:
                 count -= 1
-                self.logger.info("new_connection:exception, count=%s, message=%s", count, e)
+                self.logger.info("new_connection:exception, call_id: %s, count=%s, message=%s", self.tid, count, e)
                 time.sleep(.010)
         return _ws
 
@@ -269,7 +269,7 @@ class XfAsr:
     #     print("send end tag success")
 
     def send_audio(self, chunk):
-        self.logger.warn('xunfei.Asr.send_audio:chunk:%s, %s', len(chunk), chunk)
+        self.logger.warn('xunfei.Asr.send_audio: call_id: %s, chunk:%s, %s', self.tid, len(chunk), chunk)
         if self.ws:
             self.ws.send(chunk)
 
@@ -277,21 +277,21 @@ class XfAsr:
         if self.ws:
             self.ws.send(bytes(self.end_tag.encode('utf-8')))
             self.ws.close()
-        print("connection closed")
+        self.logger.info("connection closed call_id: %s", self.tid)
 
     def recv(self):
         try:
             # {"seg_id": 0, "cn": {"st": {"rt": [{"ws": [{"cw": [{"sc": 0.00, "w": "凭", "wp": "n", "rl": "0", "wb": 13, "wc": 0.00, "we": 26}], "wb": 0, "we": 0}]}], "bg": "9510", "type": "1", "ed": "0"}}, "ls": false}
             # {"seg_id": 1, "cn": {"st": {"rt": [{"ws": [{"cw": [{"sc": 0.00, "w": "停水", "wp": "n", "rl": "0", "wb": 26, "wc": 0.00, "we": 52}], "wb": 0,"we": 0}]}], "bg": "9770", "type": "1", "ed": "0"}}, "ls": false}
             # {"seg_id": 2, "cn": {"st": {"rt": [{"ws": [{"cw": [{"sc": 0.00, "w": "停水", "wp": "n", "rl": "0", "wb": 9, "wc": 0.00, "we": 64}], "wb": 9,"we": 64},{"cw": [{"sc": 0.00, "w": "咨询", "wp": "n", "rl": "0", "wb": 65, "wc": 0.00, "we": 132}], "wb": 65,"we": 132}]}], "bg": "9510", "type": "0", "ed": "10950"}}, "ls": false}
-            self.logger.info(f"xunfei.Asr.recv: ws.connected:{self.ws.connected}")
+            self.logger.info(f"xunfei.Asr.recv: call_id: {self.tid}, ws.connected:{self.ws.connected}")
             while self.ws and self.ws.connected:
                 message = str(self.ws.recv())
                 if len(message) == 0:
-                    self.logger.info("xunfei.Asr.recv: receive result end")
+                    self.logger.info("xunfei.Asr.recv: receive result end call_id: %s", self.tid)
                     break
 
-                self.logger.warn("xunfei.Asr.recv: message :%s", message)
+                self.logger.warn("xunfei.Asr.recv: call_id: %s, message :%s", self.tid, message)
                 if self.message_receiver:
                     self.message_receiver(self.convert_message(message))
 
@@ -314,7 +314,7 @@ class XfAsr:
                 #     return
         except Exception as e:
             traceback.print_exc()
-            self.logger.error("xunfei.Asr.recv: receive result end, %s", e)
+            self.logger.error("xunfei.Asr.recv: receive result end, call_id: %s, message: %s", self.tid, e)
 
     def convert_message(self, message):
         final_result = {}