Jelajahi Sumber

讯飞asr测试,debug

Davidliu 1 bulan lalu
induk
melakukan
f0eb0c1f43
4 mengubah file dengan 50 tambahan dan 42 penghapusan
  1. 32 32
      src/core/callcenter/config.py
  2. 15 10
      src/core/callcenter/test.py
  3. 1 0
      src/core/voip/asr.py
  4. 2 0
      src/core/voip/bot.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", "log_file"],
+#         },
+#     }
+# )

+ 15 - 10
src/core/callcenter/test.py

@@ -26,14 +26,19 @@ if __name__ == '__main__':
     #     print(custom_uuid, num, bucket.name)
 
     # message = """{"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}"""
-    message = '{"action":"result","code":"0","data":"{\"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\":\"9160\",\"type\":\"1\",\"ed\":\"0\"}},\"ls\":false}","desc":"success","sid":"rta108a8500@dx2f5f1b177d38000100"}'
-    # 解析最外层 JSON
-    message_dict = json.loads(message)
+    # message = '{"action":"result","code":"0","data":"{\"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\":\"9160\",\"type\":\"1\",\"ed\":\"0\"}},\"ls\":false}","desc":"success","sid":"rta108a8500@dx2f5f1b177d38000100"}'
+    # # 解析最外层 JSON
+    # message_dict = json.loads(message)
+    #
+    # # 解析嵌套的 JSON 字符串
+    # data = json.loads(message_dict['data'])
+    #
+    # # 提取 "w" 字段中的词汇
+    # words = ''.join(cw["w"] for item in data["cn"]["st"]["rt"] for ws in item["ws"] for cw in ws["cw"])
+    #
+    # print(words)
 
-    # 解析嵌套的 JSON 字符串
-    data = json.loads(message_dict['data'])
-
-    # 提取 "w" 字段中的词汇
-    words = ''.join(cw["w"] for item in data["cn"]["st"]["rt"] for ws in item["ws"] for cw in ws["cw"])
-
-    print(words)
+    # 读取文件
+    with open('/Users/davidliu/hot_words.txt', 'r', encoding='utf-8') as f:
+        content = f.read()
+        print(content)

+ 1 - 0
src/core/voip/asr.py

@@ -269,6 +269,7 @@ class XfAsr:
     #     print("send end tag success")
 
     def send_audio(self, chunk):
+        self.logger.info('xunfei.Asr.send_audio:chunk:%s', chunk)
         if self.ws:
             self.ws.send(chunk)
 

+ 2 - 0
src/core/voip/bot.py

@@ -615,6 +615,8 @@ class BotAgent:
             media_cfg.jbMaxPre = 16  # Maximum pre-fetch frames
             media_cfg.noVad = True  # Disable Voice Activity Detection if needed
             media_cfg.clockRate = 16000
+            media_cfg.audioFramePtime = 40
+            # media_cfg.ptime = 40
             # media_cfg.clockRate = 8000
             self.ep.medConfig = media_cfg  # Apply media config to endpoint