更新
authorp15692025051 <846603105@qq.com>
Wed, 20 Aug 2025 11:35:30 +0000 (19:35 +0800)
committerp15692025051 <846603105@qq.com>
Wed, 20 Aug 2025 11:35:30 +0000 (19:35 +0800)
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py

index 33a379f..fae4ff3 100644 (file)
@@ -41,11 +41,11 @@ except Exception as e:
     usys.print_exception(e)
     import ai_alarm as _ai_alarm
 # dev_type = "G10"
-dev_type = "7PIN_BK"#小瑞
+#dev_type = "7PIN_BK"#小瑞
 #dev_type = "7PIN_BK_coze"#k扣子小瑞
 #dev_type = "7PIN_BK_EU"#英文小瑞
 #dev_type = "7PIN_coze"#柒牌扣子
-#dev_type = "7PIN"#柒牌
+dev_type = "7PIN"#柒牌
 #dev_type = 'momo'#食梦貘
 #dev_type = 'sjgq'#四季甘泉
 #dev_type = 'szbst'#深圳百事通
@@ -216,11 +216,7 @@ class AI_UART():
     def __init__(self):
         self.AI_uart = UART(UART.UART4, 230400, 8, 0, 1, 0)
         self.AI_uart.set_callback(self.uart_call)
-        EventMesh.subscribe("led_r_open",self.led_r_open) 
-        EventMesh.subscribe("led_g_open",self.led_g_open)
-        EventMesh.subscribe("led_b_open",self.led_b_open)
-        EventMesh.subscribe("led_rgb_open",self.led_rgb_open)
-        EventMesh.subscribe("led_close",self.led_close)
+        
         EventMesh.subscribe("bt_ota_run",self.bt_ota_run)#
         EventMesh.subscribe("start_ota",self.start_ota)
         EventMesh.subscribe("end_ota",self.end_ota)
@@ -244,6 +240,8 @@ class AI_UART():
         self.ping_json_str = {}
         self.ping_json_str_tmp =""
         self.read_uart_data = ""
+        self.bt_versions=""
+        self.send_get_versions()#获取蓝牙版本
 
     def send_imei_to_ble(self,event,msg):
         EventMesh.publish("publish_AI_btnInfo",{"func":self.send_imei_to_ble_cb})
@@ -376,7 +374,11 @@ class AI_UART():
             elif jsload_data["event"] == "post_bt_connect_rest":
                 EventMesh.publish("recv_bt_connect_rest",jsload_data)
                 ack_flag=1
-
+            elif jsload_data["event"] == "versions":
+                self.bt_versions = jsload_data["data"]
+                print("当前蓝牙版本是:{}".format(self.bt_versions))
+            elif jsload_data["event"] == "kws" :#电源按键按下
+                EventMesh.publish("kws_even")
             elif jsload_data["event"] == "ack" :#电源按键按下
                 self.read_ack_flag = 1
             if ack_flag == 1:
@@ -627,7 +629,20 @@ class AI_UART():
         self.check_rest_timer_count = 0
         #print("pwk_key_release")
         EventMesh.publish("pwk_key_release")
+    def send_get_versions(self,event=None,msg=None):
+        #self.read_ack_flag = 0
+        json_data = \
+        {
+            
+            "event": "get_versions",
+        }
+        json_str  =ujson.dumps(json_data)
+        print("send_get_versions{}".format(json_str))
+        print("send_get_versions{}".format(json_str))
+        print("send_get_versions{}".format(json_str))
+        self.send_data(json_str)
 
+        pass
     def start_ota(self,event=None,msg=None):#通过串口给蓝牙升级
         EventMesh.publish("wakeup_BT") 
         print("start_ota!!!")
@@ -924,6 +939,7 @@ class AI_dev(Abstract):
     def set_speech_rate(self,event,msg):
         self.speech_rate = msg
         EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate])
+        print("set_speech_rate:{}".format(self.speech_rate))
     def btnInfo_queue_thread(self):
         while True:
             data = self.btnInfo_queue.get()
@@ -1145,6 +1161,7 @@ class AI_dev(Abstract):
             usys.print_exception(e) 
        
     def AI_key_press(self):
+        EventMesh.publish("wakeup_BT")
         self.check_rest_timer_count = 0
         print("AI_key_press")
         EventMesh.publish("AI_key_press")
@@ -1299,6 +1316,7 @@ class AI_dev(Abstract):
     #鉴权出错,播放imei号
     def paly_device_res_error(self,event,msg):
         self.wakeup_BT()
+        EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
         str_data = 'mp3files={}.mp3+'.format(audio_buf.index("jianquancuowu"))#AI功能异常,请联系客户查询,设备号为:
         imei  = modem.getDevImei()
         imei = imei.upper()
@@ -2030,6 +2048,7 @@ class AI_VC(Abstract):
             usys.print_exception(e)
         self.VC_30S_timer = osTimer()
         self.VC_30S_timer.start(30000, 1, self.VC_30S_timer_cb)
+        self.online_kws = 1#是否开启线上关键词
         self.get_config_timer_count = 0
         self.record_data_save_flag = 0 #是否保存录音文件
         self.play_data_save_flag = 0#是否保存tts数据到文件
@@ -2050,6 +2069,7 @@ class AI_VC(Abstract):
         EventMesh.subscribe("play_tts",self.play_tts)
         EventMesh.subscribe("play_new_voice",self.play_new_voice)
         EventMesh.subscribe("set_vad_silence",self.set_vad_silence)
+        EventMesh.subscribe("kws_even",self.kws_even)
             
         
         self.error_data = []
@@ -2087,7 +2107,8 @@ class AI_VC(Abstract):
                 # self.server_ip="220.160.104.34"
                 # self.server_ip="118.145.158.207:22082"
                 # self.server_ip="118.145.158.207:22080/22087"
-                self.server_ip="ai.qipai.com"
+                #self.server_ip="ai.qipai.com"
+                self.server_ip="dmp.qipai.com.cn:30746"
                 #self.server_ip="sevenpin1.qipai.com.cn:22082"
             elif dev_type == "G10":
                 self.server_ip="115.190.94.208:22080"
@@ -2202,192 +2223,6 @@ class AI_VC(Abstract):
                                             "lang":"zh-cn" 
                                             }
                                            
-                                        }
-            elif  dev_type == "7PIN_BK_coze":
-                self.VC_TTS_voice_type = {   
-                                            "女":{
-                                            "bot_name":"小瑞",
-                                            "voice":"7468518753626488869" ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "男":{
-                                            "bot_name":"小瑞",
-                                            "voice":"7426720361732980745"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "童":{
-                                            "bot_name":"小瑞",
-                                            "voice":"7468512265151676443"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "粤":{
-                                            "bot_name":"啊瑞",
-                                            "voice":"7481299960428888103" ,
-                                            "lang":"zh-hk" 
-                                            },
-                                            "四川":{
-                                            "bot_name":"小瑞",
-                                            "voice":"7426720361732931593",
-                                            "lang":"&lang=zh-cn-sc"  
-                                            },
-                                            "个性":{
-                                            "bot_name":"小瑞",
-                                            "voice":"7468512265134850099" ,
-                                            "lang":"zh-cn" 
-                                            }
-                                           
-                                        }
-            elif  dev_type == "7PIN_BK_EU":
-                                            self.VC_TTS_voice_type = {   
-                                            "女":{
-                                            "bot_name":"Rose",
-                                            "voice":"zh_female_shuangkuaisisi_emo_v2_mars_bigtts" ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "男":{
-                                            "bot_name":"Jack",
-                                            "voice":"zh_male_wennuanahu_moon_bigtts"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "童":{
-                                            "bot_name":"Ray",
-                                            "voice":"zh_female_mengyatou_mars_bigtts"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                           
-                                        }
-            elif dev_type == "csh":
-                self.VC_TTS_voice_type = {   
-                                            "女":{
-                                            "bot_name":"小福",
-                                            "voice":"zh_female_wanwanxiaohe_moon_bigtts" ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "男":{
-                                            "bot_name":"小福",
-                                            "voice":"zh_male_wennuanahu_moon_bigtts"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "童":{
-                                            "bot_name":"小福",
-                                            "voice":"ICL_zh_female_huoponvhai_tob"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "粤":{
-                                            "bot_name":"小福",
-                                            "voice":"zh_female_wanqudashu_moon_bigtts" ,
-                                            "lang":"zh-hk" 
-                                            },
-                                            "四川":{
-                                            "bot_name":"小福",
-                                            "voice":"zh_female_daimengchuanmei_moon_bigtts",
-                                            "lang":"&lang=zh-cn-sc"  
-                                            },
-                                        }
-            elif dev_type == 'jswm'or dev_type == 'jswm_BOX':
-                self.VC_TTS_voice_type = {   
-                                            
-                                            "林悦":{
-                                            "bot_name":"林悦",
-                                            #"voice":"ICL_zh_female_xingganyujie_tob",
-                                            "voice":"zh_female_yuanqinvyou_moon_bigtts" ,
-                                            "lang":"&lang=zh-cn-sc"  ,
-                                            "bot_id":"7490824341572075555",#AI语音APP女神经理
-                                            "workflow_id":"",
-                                            "openai_option":{
-                                                # "model": "intimate-pro-32k-250115",
-                                                # "system":{
-                                                #     "type": "file",
-                                                #     "content": "1567d9e19ac09269d8ce6c887494ff01",
-                                                # },
-                                            },
-
-                                            },
-                                            "黄文新":{
-                                            "bot_name":"黄文新",
-                                            "voice":"zh_male_wennuanahu_moon_bigtts" ,           
-                                            "lang":"zh-cn" ,
-                                            "bot_id":"7490825075302973440",#开朗男友
-                                            "workflow_id":"",
-                                            "openai_option":{
-                                                # "model": "intimate-pro-32k-250115",
-                                                # "system":{
-                                                #     "type": "file",
-                                                #     "content": "2731e1e9d7150807795c4b5ab1e01e1b",
-                                                # },
-                                            },
-                                            },
-                                           
-                                        }
-            elif dev_type == 'momo':
-                self.VC_TTS_voice_type = {   
-                                            "女":{
-                                            "bot_name":"食梦貘",
-                                            "voice":"zh_female_linjia_mars_bigtts" ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "男":{
-                                            "bot_name":"食梦貘",
-                                            "voice":"zh_male_yangguangqingnian_mars_bigtts"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "童":{
-                                            "bot_name":"食梦貘",
-                                            "voice":"ICL_zh_female_huoponvhai_tob"  ,
-                                            "lang":"zh-cn"
-                                            },
-                }
-            elif dev_type == 'sjgq':
-                self.VC_TTS_voice_type = {   
-                                            "女":{
-                                            "bot_name":"小巴",
-                                            "voice":"zh_female_wanwanxiaohe_moon_bigtts" ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "男":{
-                                            "bot_name":"小巴",
-                                            "voice":"zh_male_wennuanahu_moon_bigtts"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "童":{
-                                            "bot_name":"小巴",
-                                            "voice":"ICL_zh_female_huoponvhai_tob"  ,
-                                            "lang":"zh-cn"
-                                            },
-                }
-            elif  dev_type == "7PIN_coze":
-                self.VC_TTS_voice_type = {   
-                                            "女":{
-                                            "bot_name":"柒妹妹",
-                                            "voice":"7468518753626488869" ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "男":{
-                                            "bot_name":"柒先生",
-                                            "voice":"7426720361732980745"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "童":{
-                                            "bot_name":"柒乐乐",
-                                            "voice":"7468512265151676443"  ,
-                                            "lang":"zh-cn"
-                                            },
-                                            "粤":{
-                                            "bot_name":"柒先生",
-                                            "voice":"7481299960428888103" ,
-                                            "lang":"zh-hk" 
-                                            },
-                                            "四川":{
-                                            "bot_name":"柒妹妹",
-                                            "voice":"7426720361732931593",
-                                            "lang":"&lang=zh-cn-sc"  
-                                            },
-                                            "个性":{
-                                            "bot_name":"柒先生",
-                                            "voice":"7468512265134850099" ,
-                                            "lang":"zh-cn" 
-                                            }
-                                           
                                         }
             else:
                 #女,男,童,粤,川,个性声
@@ -2395,37 +2230,44 @@ class AI_VC(Abstract):
                                             "女":{
                                             "bot_name":"柒妹妹",
                                             "voice":"zh_female_wanwanxiaohe_moon_bigtts" ,
-                                            "lang":"zh-cn"
+                                            "outbound_attributess_provider":"volcengine",
+                                            "inbound_attributess_provider":"xun-fei"
                                             },
                                             "男":{
                                             "bot_name":"柒先生",
                                             "voice":"zh_male_wennuanahu_moon_bigtts"  ,
-                                            "lang":"zh-cn"
+                                            "outbound_attributess_provider":"volcengine",
+                                            "inbound_attributess_provider":"xun-fei"
                                             },
                                             "童":{
                                             "bot_name":"柒乐乐",
                                             "voice":"ICL_zh_female_huoponvhai_tob"  ,
-                                            "lang":"zh-cn"
+                                            "outbound_attributess_provider":"volcengine",
+                                            "inbound_attributess_provider":"xun-fei"
                                             },
                                             "粤":{
                                             "bot_name":"柒先生",
                                             "voice":"zh_female_wanqudashu_moon_bigtts" ,
-                                            "lang":"zh-hk" 
+                                            "outbound_attributess_provider":"volcengine",
+                                            "inbound_attributess_provider":"xun-fei"
                                             },
                                             "四川":{
                                             "bot_name":"柒妹妹",
                                             "voice":"zh_female_daimengchuanmei_moon_bigtts",
-                                            "lang":"&lang=zh-cn-sc"  
+                                            "outbound_attributess_provider":"volcengine",
+                                            "inbound_attributess_provider":"xun-fei"
                                             },
                                             "个性":{
                                             "bot_name":"柒先生",
                                             "voice":"zh_male_sunwukong_mars_bigtts" ,
-                                            "lang":"zh-cn" 
+                                            "outbound_attributess_provider":"volcengine",
+                                            "inbound_attributess_provider":"xun-fei"
                                             },
                                             "英语":{
                                             "bot_name":"柒先生",
                                             "voice":"en_male_smith_mars_bigtts" ,
-                                            "lang":"zh-cn" 
+                                            "outbound_attributess_provider":"volcengine",
+                                            "inbound_attributess_provider":"xun-fei"
                                             }
                                             
                                            
@@ -2461,170 +2303,7 @@ class AI_VC(Abstract):
         self.commands_mode = 2 #=1用大模型判断命令,=0用服务器本地插件判断命令 =2用设备本地判断方式
         if dev_type == "7PIN_BK"or dev_type == "7PIN_BK_EU"or dev_type == "7PIN_BK_coze":
             self.commands_mode = 2
-        self.commands =  [
-            {
-                "command": "切换音色",#命令
-                "patterns": [ #多种问法,说法
-                    "声音改成", "声音改为", "改成", "改为", "换成", "切换成", "变成", "声音"
-                    "使用", "设置声音为", "把声音改成", "声音切换到", "用","声音切换的"
-                ],
-                "exact_matches": ["声音改成", "声音改为", "改成", "改为"],#精确匹配的完整短语
-                "has_param": True,# 是否包含参数
-                "param_regexp": r"(?P<cmd_parameter>(男|难|女|童|同|粤|广东话|粤语|四川话|川普|四川口音))",#参数提取正则表达式
-                "require_full_match": False,#是否要求完全匹配
-                "negative_patterns": [],#否定模式(避免误触发)
-                "keyword_threshold": 0.6#关键词匹配阈值
-            },
-            {
-                "command": "音量加大",
-                "patterns": [
-                    "音量加大","音量大", "声音大" ,"声音加大","听不清楚","声音太小","太小声了"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": ["声音太大"],
-                "keyword_threshold": 1
-            },
-            {
-                "command": "音量减小",
-                "patterns": [
-                    "音量减小","音量小", "声音小","你太吵了","声音太大","太大声了"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": ["声音太小"],
-                "keyword_threshold": 0.8
-            },
-            {
-                "command": "关机",
-                "patterns": [
-                    "关机", "关闭电源"
-                ],
-                "exact_matches": ["关机", "关闭电源"],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": True,
-                "negative_patterns": [],
-                "keyword_threshold": 0.8
-            },
-            {
-                "command": "进入工厂模式",
-                "patterns": [
-                    "进入工厂模式"
-                ],
-                "exact_matches": ["进入工厂模式"],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": True,
-                "negative_patterns": [],
-                "keyword_threshold": 0.8
-            },
-            {
-            
-                "command": "再见",
-                "patterns": [
-                    "再见","拜拜","我要走了"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": [],
-                "keyword_threshold": 0.8
-            },
-            {
-            
-                "command": "查询信号",
-                "patterns": [
-                    "查询信号","信号怎样","信号是多少","信号怎么样"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": ["查询"],
-                "keyword_threshold": 0.8
-            },   
-            {
-            
-                "command": "查询卡号",
-                "patterns": [
-                    "查询卡号","卡号","iccid号","ICCID号"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": ["查询"],
-                "keyword_threshold": 0.8
-            },  
-            {
-            
-                "command": "查询设备号",
-                "patterns": [
-                    "设备号","查询设备号","查询IMEI号"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": ["查询"],
-                "keyword_threshold": 0.8
-            },
-            {
-                "command": "OTA升级",
-                "patterns": [
-                    "OTA升级"
-                ],
-                "exact_matches": ["OTA升级"],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": True,
-                "negative_patterns": [],
-                "keyword_threshold": 1
-            },    
-            {
-                "command": "查询服务器地址",
-                "patterns": [
-                    "查询服务器地址"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": ["查询"],
-                "keyword_threshold": 0.9
-            }   
-            ,    
-            {
-                "command": "切换对话模式",
-                "patterns": [
-                    "切换对话模式","切换兑换模式"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": [],
-                "keyword_threshold": 0.8
-            },  
-            {
-                "command": "查询版本",
-                "patterns": [
-                    "查询版本号","软件版本"
-                ],
-                "exact_matches": [],
-                "has_param": False,
-                "param_regexp": "",
-                "require_full_match": False,
-                "negative_patterns": ["查询"],
-                "keyword_threshold": 0.6
-            }, 
-        ]
+        self.commands = []
         if self.VC_TTS_volume == None:
             self.VC_TTS_volume = 100
         self.AI_audio_queue_thread_id = 0
@@ -2706,6 +2385,7 @@ class AI_VC(Abstract):
         self.tts_in_data_len = 0
         self.tts_out_data_len = 0
         self.VC_satrt_flag = 0
+        self.VC_satrt_kws_flag = 0
         self.session_id = ""
         EventMesh.subscribe("AI_key_press", self.AI_key_press)
         EventMesh.subscribe("stop_AI_record", self.stop_AI_record)
@@ -2718,6 +2398,8 @@ class AI_VC(Abstract):
         EventMesh.subscribe("audio_test", self.audio_test)
         EventMesh.subscribe("audio_test_close", self.audio_test_close)
         EventMesh.subscribe("set_record_data_save_flag", self.set_record_data_save_flag)
+        EventMesh.subscribe("set_VC_TTS_voice_type", self.set_VC_TTS_voice_type)
+        
         EventMesh.publish("close_led")
         self.dialog_attributes_provider =  EventMesh.publish("get_storage_config","dialog_attributes_provider")#智能体类型配置
         if self.dialog_attributes_provider == None:
@@ -2731,6 +2413,7 @@ class AI_VC(Abstract):
                 self.inbound_attributess_provider = "xun-fei"
             else:
                 self.inbound_attributess_provider = "volcengine"
+        
         self.bot_name = "柒先生"
         try:
             if "bot_name" in self.VC_TTS_voice_type[self.VC_TTS_voice_key]:
@@ -2901,7 +2584,7 @@ class AI_VC(Abstract):
             #EventMesh.publish("set_audio_state", 0)   
             print('audio-play finish.!!!!!!')
 
-    def AI_key_press(self, event, msg):#按键按下
+    def AI_key_press(self, event=None, msg = None):#按键按下
         if self.voice_flag == 1: #语音留言模式
            # EventMesh.publish("stop_AI_record")
             self.Close()
@@ -2914,8 +2597,8 @@ class AI_VC(Abstract):
         self.get_config_timer_count = 0
         self.key_state = 1
         self.Close()
-        # if dev_type == "7PIN" :
-        #     self.aud.aud_tone_play(10,200)#播放按键音
+        if dev_type == "7PIN" :
+            self.aud.aud_tone_play(10,200)#播放按键音
         #self.aud.aud_tone_play(10,200)#播放按键音
         self.AI_TTS_str = ""#"你好,有什么吩咐"
         self.AI_ASR_str = ""
@@ -2934,7 +2617,7 @@ class AI_VC(Abstract):
         # self.Close()
         # self.AI_VC_start()
         self.AI_key_long_press_flag = 0
-    def stop_AI_record(self, event, msg):#停止AI对话
+    def stop_AI_record(self, event=None, msg=None):#停止AI对话
         if self.VC_satrt_flag == 1:
             self.get_config_timer_count = 0
             self.AI_TTS_str = ""#"你好,有什么吩咐"
@@ -2952,7 +2635,7 @@ class AI_VC(Abstract):
 
        
 
-    def AI_key_release(self, event, msg):#按键弹起
+    def AI_key_release(self, event=None, msg=None):#按键弹起
         print("AI_key_release123")
         self.key_state = 0
         if self.voice_flag == 1:
@@ -2997,7 +2680,7 @@ class AI_VC(Abstract):
         print("pwk_key_release")
         EventMesh.publish("publish_AI_btnInfo",{"func":self.Close}) 
         EventMesh.publish("stop_sos_call")
-        EventMesh.publish("sleep_BT")#休眠蓝牙
+        #EventMesh.publish("sleep_BT")#休眠蓝牙
 
     def key_prompt(self):
         EventMesh.publish("audio_montage_play",["key_prompt.mp3"])
@@ -3647,7 +3330,7 @@ class AI_VC(Abstract):
                                 self.AI_TTS_str = ""    
                             else:
                                 #开始上传语音
-                                if dev_type != "7PIN_coze":
+                                if dev_type != "7PIN_coze" and dev_type != "7PIN" :
                                     self.chenggong_tone()
                                 if self.VC_mode == 0    :
                                     self.VC_record_state_flag  =2
@@ -4564,7 +4247,9 @@ class AI_VC(Abstract):
                         self.VC_state = VC_State_None
                     #通知服务器播放结束
                     #self.AI_client_VC_LocalRespondingEnded()
-
+        if self.online_kws == 1:
+            if self.VC_satrt_kws_flag == 1 and self.VC_satrt_flag == 0:#要打开录音上传数据实现kws
+                pass
         self.VC_pingping_timerout+=1
         if self.VC_pingping_timerout>3:
             self.VC_pingping_timerout=0
@@ -4582,12 +4267,20 @@ class AI_VC(Abstract):
                 self.VC_state = VC_State_None
                 EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start}) 
                 pass
-        
+    # def AI_kws_start(self):    
+    #     print("AI_kws_start")
+    #     EventMesh.publish("wakeup_BT")
+    #     EventMesh.publish("system_sleep_rest")#防止黑屏
+    #     url="ws://118.145.158.207:22080/wakeup/ws"
+    #     self.AI_client_kws = uwebsocket.Client.connect(url, debug=True)
+    #     self.AI_client_VC_recv_id = _thread.start_new_thread(self.AI_client_VC_recv, (self.AI_client_VC,))
+    #     self.VC_Speech_Start()#开启线程获取录音数据
     #VC开始
     def AI_VC_start(self):
         print("AI_VC_start1")
         EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
         self.VC_satrt_flag = 1
+        self.VC_satrt_kws_flag = 1
         if self.VC_Thinking_timerout < 100:
             self.VC_Thinking_timerout = 0
         EventMesh.publish("open_led_all")
@@ -4709,6 +4402,8 @@ class AI_VC(Abstract):
                     "interrupt_options":{
                         "concatenate_results":True,
                         "thinking_time_only": True,
+                        #"keyword_interrupt": false, // 启用打断词功能 (打断词只有在思考以及之后才能打断)
+                        #"interrupt_keywords": ["停止", "打断","打断一下", "等一下", "别说了", "打住"] // 配置打断词列表
                     },
                     "cfg": {
                         "format": "pcm",
@@ -4731,8 +4426,22 @@ class AI_VC(Abstract):
         # "workflow_id":"7469968083063603241",
         # "bot_id":"7411071327182438412",#柒牌
         # "workflow_id":"7469049680291610636",
+        # if self.online_kws == 1:#打开
+        #     json_data["payload"]["inbound_attributes"]["interrupt_options"]["keyword_interrupt"] = True
+        #     json_data["payload"]["inbound_attributes"]["interrupt_options"]["interrupt_keywords"] = ["你好,柒先生","你好"]
+        #如果
         json_data["payload"]["outbound_attributes"]["provider"]=self.outbound_attributess_provider#TTS音色服务选择,火山
         json_data["payload"]["inbound_attributes"]["provider"]=self.inbound_attributess_provider#ASR服务选择,火山
+        #优先选择self.VC_TTS_voice_type[self.VC_TTS_voice_key]里得参数
+        if "inbound_attributess_provider" in self.VC_TTS_voice_type[self.VC_TTS_voice_key]:
+            if len(self.VC_TTS_voice_type[self.VC_TTS_voice_key]["inbound_attributess_provider"])>0:
+                json_data["payload"]["inbound_attributes"]["provider"]=self.VC_TTS_voice_type[self.VC_TTS_voice_key]["inbound_attributess_provider"]
+                print("inbound_attributess_provider是VC_TTS_voice_type里的:{}".format(self.VC_TTS_voice_type[self.VC_TTS_voice_key]["inbound_attributess_provider"]))
+        if "outbound_attributess_provider" in self.VC_TTS_voice_type[self.VC_TTS_voice_key]:
+            if len(self.VC_TTS_voice_type[self.VC_TTS_voice_key]["outbound_attributess_provider"])>0:
+                json_data["payload"]["outbound_attributes"]["provider"]=self.VC_TTS_voice_type[self.VC_TTS_voice_key]["outbound_attributess_provider"]
+                print("outbound_attributess_provider是VC_TTS_voice_type里的:{}".format(self.VC_TTS_voice_type[self.VC_TTS_voice_key]["outbound_attributess_provider"]))
+
         if dev_type == "7PIN_BK"or dev_type == "7PIN_BK_coze"or dev_type == "G10":#小瑞
             json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["bot_id"]="7411071327182438412"#语言助手
             json_data["payload"]["dialog_attributes"]["cfg"]["bot_option"]["workflow_id"]="7468577560454496295"
@@ -4883,6 +4592,23 @@ class AI_VC(Abstract):
         # if self.VC_state == VC_State_RequestToRespond:
         #     print("AI_client_VC_RequestToRespond 重复 tts_str:{}\nasr_str:{}".format(self.AI_TTS_str,self.AI_ASR_str))
         self.AI_client_VC_send(ujson.dumps(json_data))
+    def kws_even(self,event = None,msg= None):
+        EventMesh.publish("publish_AI_btnInfo",{"func":self.kws_even_cb}) 
+    def kws_even_cb(self):
+        print("kws_even_cb")
+        if self.VC_mode == 0:
+            self.Close()
+            if dev_type == "7PIN" :
+                self.aud.aud_tone_play(10,200)#播放按键音
+            #self.aud.aud_tone_play(10,200)#播放按键音
+            self.AI_TTS_str = ""#"你好,有什么吩咐"
+            self.AI_ASR_str = ""
+            self.AI_ASR_str_tmp = ""
+            self.VC_state = VC_State_None
+            self.VC_Speech_End()
+            self.VC_Speech_Start()    
+            self.AI_VC_start() 
+
     def set_vad_silence(self,event = None,msg= None):
         self.vad_silence = msg
         EventMesh.publish("set_storage_config",["vad_silence",self.vad_silence])  
@@ -4894,6 +4620,8 @@ class AI_VC(Abstract):
         self.VC_TTS_voice_key = "APP_voice"
         EventMesh.publish("set_storage_config",["VC_TTS_voice_type",self.VC_TTS_voice_type])
         EventMesh.publish("set_storage_config",["VC_TTS_voice_key",self.VC_TTS_voice_key])
+        print("VC_TTS_voice_type:{}".format(self.VC_TTS_voice_type))
+        print("VC_TTS_voice_key:{}".format(self.VC_TTS_voice_key))
     def play_new_voice(self,event = None,msg= None):
         EventMesh.publish("publish_AI_btnInfo",{"func":self.play_new_voice_cb,"data":msg}) 
     def play_new_voice_cb(self,data):
@@ -4918,7 +4646,7 @@ class AI_VC(Abstract):
             # EventMesh.publish("publish_AI_btnInfo",{"func":self.websocket_deconnect_VC}) 
             # EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start}) 
         except Exception as e:
-            usys.print_exception(e)   
+                usys.print_exception(e)   
         pass
     def AI_client_new_voice(self): #上传未读的语音地址
         json_data = \
@@ -5068,7 +4796,9 @@ class AI_VC(Abstract):
 
     def Close(self):
         self.VC_Thinking_timerout = 0
-        
+        self.AI_ASR_timer.stop()
+        self._1S_timer.stop()
+        self.factory_timer.stop()
         self.AI_TTS_str = ""
         self.AI_ASR_str = ""
         self.AI_ASR_str_tmp = ""
@@ -5111,9 +4841,7 @@ class AI_VC(Abstract):
         print("ai_VC Close2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
         
         
-        self.AI_ASR_timer.stop()
-        self._1S_timer.stop()
-        self.factory_timer.stop()
+        
         
         if self.record_data_save_flag == 1:
             if self.record_fd :
index bfb1c34..a31902b 100644 (file)
@@ -2791,20 +2791,35 @@ class IOTWeb_chat_configProtoCol(ProtoCol):
 
         if "data" in msg:
             data = msg["data"]
-            speed = data["speed"]
+            speed = None
+            try:
+                speed = int(data["speed"])
+            except Exception as e:
+                usys.print_exception(e)
             vadDuration = data["vadDuration"]
             voiceId = data["voiceId"]
             provider = data["provider"]
+            botName = data["botName"]
+            asr =  data["asr"]
             if speed !=  None:
-                if len(speed) != 0:
                     EventMesh.publish("SET_SPEECH_RATE",speed)
             if vadDuration != None:
-                if len(vadDuration) != 0:
+                #if len(vadDuration) != 0:
                     EventMesh.publish("set_vad_silence",vadDuration)
-            if provider != None:
-                if len(provider) != 0:
-                    pass
-                    # EventMesh.publish("set_vad_silence",vadDuration)
+            tts_type = {}
+            if voiceId != None and len(voiceId) != 0:
+                tts_type["voice"] = voiceId
+            if provider != None and len(provider) != 0:
+                tts_type["outbound_attributess_provider"] = provider
+            if botName != None and len(botName) != 0:
+                tts_type["bot_name"] = botName
+            if voiceId != None and len(voiceId) != 0:
+                tts_type["voice"] = voiceId
+            if asr != None and len(asr) != 0:
+                tts_type["inbound_attributess_provider"] = asr
+            if len(tts_type)>0:
+                print("tts_type:{}".format(tts_type))
+                EventMesh.publish("set_VC_TTS_voice_type",tts_type)
         EventMesh.publish(WEB_CMD_ENUM.CHAT_CONFIG_S)
 #获取AI对话音色配置
 class IOTWeb_get_chat_configProtoCol(ProtoCol):