Browse Source

讯飞asr测试,debug

Davidliu 1 month ago
parent
commit
1b6dc8f52f
2 changed files with 50 additions and 38 deletions
  1. 5 38
      src/core/voip/bot.py
  2. 45 0
      src/core/voip/constant.py

+ 5 - 38
src/core/voip/bot.py

@@ -596,58 +596,25 @@ class BotAgent:
         try:
             self.cache.set_register_per_hours(expire=timeout_sec - (60*3))
             # Create and initialize the library
-            ep_cfg = pj.EpConfig()
-            ep_cfg.uaConfig.threadCnt = 4
-            ep_cfg.uaConfig.mainThreadOnly = False
-            ep_cfg.uaConfig.maxCalls = 12
-            ep_cfg.uaConfig.maxAccounts = 12
-            ep_cfg.medConfig.noVad = True
-            ep_cfg.logConfig.level = 3
-            ep_cfg.logConfig.consoleLevel = 3
+            ep_cfg = build_ep_config()
             self.ep.libCreate()
             self.ep.libInit(ep_cfg)
 
             aud_dev_mgr = self.ep.audDevManager()
             aud_dev_mgr.setNullDev()  # 使用虚拟音频设备(如果没有实际设备)
+
             # Set up media configuration, particularly jitter buffer
-            media_cfg = pj.MediaConfig()
-            media_cfg.jbMinPre = 4  # Minimum pre-fetch frames
-            media_cfg.jbMaxPre = 16  # Maximum pre-fetch frames
-            media_cfg.noVad = True  # Disable Voice Activity Detection if needed
-            media_cfg.clockRate = 16000
-            media_cfg.channelCount = 1
-            media_cfg.audioFramePtime = 40
-            # media_cfg.ptime = 40
-            # media_cfg.clockRate = 8000
+            media_cfg = build_media_config()
             self.ep.medConfig = media_cfg  # Apply media config to endpoint
 
             # Create SIP transport. Error handling sample is shown
-            sipTpConfig = pj.TransportConfig()
-            sipTpConfig.port = 30506
+            sipTpConfig = build_sip_transport_config()
             self.ep.transportCreate(pj.PJSIP_TRANSPORT_UDP, sipTpConfig)
             # Start the library
             self.ep.libStart()
 
             for user_part in self.user_part_range:
-                acfg = pj.AccountConfig()
-                acfg.idUri = f"sip:{user_part}@{self.host}:{self.port}"
-                acfg.regConfig.registrarUri = f"sip:{self.host}:{self.port}"
-                cred = pj.AuthCredInfo("digest", "*", f"{user_part}", 0, self.password)
-                acfg.sipConfig.authCreds.append(cred)
-
-                acfg.regConfig.timeoutSec = timeout_sec  # 注册超时时间(秒)
-                acfg.regConfig.retryIntervalSec = 10  # 重试间隔时间(秒)
-                acfg.regConfig.firstRetryIntervalSec = 10  # 首次重试间隔时间(秒)
-
-                acfg.natConfig.iceEnabled = True
-                acfg.natConfig.turnEnabled = True
-                acfg.natConfig.turnServer = f"stun:{self.host}:3478"
-                # acfg.natConfig.turnUsername = "username"
-                # acfg.natConfig.turnPassword = "password"
-                acfg.natConfig.udpKaIntervalSec = 30
-                acfg.natConfig.contactRewriteUse = 2
-                acfg.natConfig.sdpNatRewriteUse = 2
-
+                acfg = build_account_config(self.host, self.port, user_part, self.password, timeout_sec)
                 # Create the account
                 acc = Account(self, user_part=user_part)
                 acc.create(acfg)

+ 45 - 0
src/core/voip/constant.py

@@ -14,6 +14,51 @@ def murmur3_32(player_file):
         player_file = ','.join(player_file)
     return abs(mmh3.hash(player_file))
 
+def build_ep_config():
+    ep_cfg = pj.EpConfig()
+    ep_cfg.uaConfig.threadCnt = 4
+    ep_cfg.uaConfig.mainThreadOnly = False
+    ep_cfg.uaConfig.maxCalls = 12
+    ep_cfg.uaConfig.maxAccounts = 12
+    ep_cfg.medConfig.noVad = True
+    ep_cfg.logConfig.level = 3
+    ep_cfg.logConfig.consoleLevel = 3
+    return ep_cfg
+
+def build_media_config():
+    media_cfg = pj.MediaConfig()
+    media_cfg.jbMinPre = 4  # Minimum pre-fetch frames
+    media_cfg.jbMaxPre = 16  # Maximum pre-fetch frames
+    media_cfg.noVad = True  # Disable Voice Activity Detection if needed
+    media_cfg.clockRate = 16000
+    media_cfg.channelCount = 1
+    media_cfg.audioFramePtime = 40
+    return media_cfg
+
+def build_sip_transport_config():
+    sip_transport_cfg = pj.TransportConfig()
+    sip_transport_cfg.port = 30506
+    return sip_transport_cfg
+
+def build_account_config(host, port, user_part, password, timeout_sec):
+    acfg = pj.AccountConfig()
+    acfg.idUri = f"sip:{user_part}@{host}:{port}"
+    acfg.regConfig.registrarUri = f"sip:{host}:{port}"
+    cred = pj.AuthCredInfo("digest", "*", f"{user_part}", 0, password)
+    acfg.sipConfig.authCreds.append(cred)
+
+    acfg.regConfig.timeoutSec = timeout_sec  # 注册超时时间(秒)
+    acfg.regConfig.retryIntervalSec = 10  # 重试间隔时间(秒)
+    acfg.regConfig.firstRetryIntervalSec = 10  # 首次重试间隔时间(秒)
+
+    acfg.natConfig.iceEnabled = True
+    acfg.natConfig.turnEnabled = True
+    acfg.natConfig.turnServer = f"stun:{host}:3478"
+    # acfg.natConfig.turnUsername = "username"
+    # acfg.natConfig.turnPassword = "password"
+    acfg.natConfig.udpKaIntervalSec = 30
+    acfg.natConfig.contactRewriteUse = 2
+    acfg.natConfig.sdpNatRewriteUse = 2
 
 def build_audio_format():
     fmt = pj.MediaFormatAudio()