语音留言加提示灯
authordxy <1731678236qq.com>
Tue, 26 Aug 2025 10:04:07 +0000 (18:04 +0800)
committerdxy <1731678236qq.com>
Tue, 26 Aug 2025 10:04:07 +0000 (18:04 +0800)
sos紧急呼叫处理播放拨打的号码

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 c66fb73..d994603 100644 (file)
@@ -230,6 +230,7 @@ class AI_UART():
         EventMesh.subscribe("recv_bt_connect_rest",self.recv_bt_connect_rest)
         EventMesh.subscribe("AI_send_bt_ble_switch_toble",self.AI_send_bt_ble_switch_toble)
         EventMesh.subscribe("get_bt_versions",self.get_bt_versions)
+        EventMesh.subscribe("clear_earphone_record",self.clear_earphone_record)
         self.bt_switch = 0
         self.ble_switch = 0
         self.uart_timer = osTimer()
@@ -375,6 +376,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"] == "clear_earphone_record_ok":
+                tts_play_str = "删除成功"
+                EventMesh.publish("play_tts",[tts_play_str,1])
+                ack_flag=1
+            
             elif jsload_data["event"] == "versions":
                 self.bt_versions = jsload_data["data"]
                 print("当前蓝牙版本是:{}".format(self.bt_versions))
@@ -396,6 +402,16 @@ class AI_UART():
             pass
     def get_bt_versions(self,event=None,msg=None):
         return self.bt_versions
+    def clear_earphone_record(self,event,msg): #清楚所有耳机记录
+
+        json_data = \
+        {
+            "event": "clear_earphone_record",
+        }
+        json_str  =ujson.dumps(json_data)
+        print("clear_earphone_record{}".format(json_str))
+        self.send_data(json_str)
+
     def AI_send_bt_ble_switch_toble(self,event,msg):
         # // {
         #     //     "event":"switch_bt_state",
@@ -1136,8 +1152,8 @@ class AI_dev(Abstract):
                     self.KeyAI_timer.start(100, 1, self.KeyAI_timer_cb)
                     self.KeyAI_timer_count = 0
                     #EventMesh.publish("AI_key_press")
-                    if dev_type == "7PIN" or dev_type == "7PIN_coze" :
-                        self.aud.aud_tone_play(10,200)#播放按键音
+                    # if dev_type == "7PIN" or dev_type == "7PIN_coze" :
+                    #     self.aud.aud_tone_play(10,400)#播放按键音
                     EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_key_press})  
         except Exception as e: 
             usys.print_exception(e)
@@ -1186,7 +1202,7 @@ class AI_dev(Abstract):
         self.KeySOS_timer_flag = 0
         if self.KeySOS_timer_count >= 3:
             self.KeySOS_timer_count = 0
-            get_sos_flag = EventMesh.publish("get_sos_flag") 
+            get_sos_flag = EventMesh.publish("get_sos_flag")
             if get_sos_flag == 0:
                 EventMesh.publish("set_sos_info_call")
         self.KeySOS_timer_count = 0
@@ -2701,20 +2717,21 @@ class AI_VC(Abstract):
         self.aud.setVolume(self.VC_TTS_volume //10)
         pass
     def AI_key_press(self, event=None, msg = None):#按键按下
+        EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
         if self.voice_flag == 1: #语音留言模式
            # EventMesh.publish("stop_AI_record")
             self.Close()
+            EventMesh.publish("open_led_green")
             EventMesh.publish("start_voice_record",2)#停止静默录音
             return
-        if EventMesh.publish("get_sos_flag") == 1:
+        if EventMesh.publish("get_sos_flag")== 1:
             return 
         EventMesh.publish("stop_voice_record") #开启静默需要关闭
         print("AI_key_press")
         self.get_config_timer_count = 0
         self.key_state = 1
         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 = ""
@@ -2727,7 +2744,10 @@ class AI_VC(Abstract):
         self.VC_Speech_End()
 
         self.VC_Speech_Start()    
+        
         self.AI_VC_start() 
+        if dev_type == "7PIN" :
+            self.aud.aud_tone_play(10,400)#播放按键音
         # if dev_type != "7PIN":
         #     self.chenggong_tone()
         # self.Close()
@@ -2756,6 +2776,8 @@ class AI_VC(Abstract):
         self.key_state = 0
         if self.voice_flag == 1:
             self.voice_flag=0
+            if EventMesh.publish("GET_USB_STATE") == 0:
+                EventMesh.publish("close_led")
             EventMesh.publish("stop_voice_record")#停止静默录音
             return
         if self.AI_key_long_press_flag == 1 :#有长按
@@ -4220,6 +4242,13 @@ class AI_VC(Abstract):
                     EventMesh.publish("send_unbind_dev_to_iot")
                     print("解绑设备!!!!!!!!!!!!!!")
                     return 0
+                if text.find("删除耳机记录") != -1 or text.find("清楚耳机记录") != -1:
+                    
+                    self.AI_TTS_str = "正在删除" 
+                    EventMesh.publish("clear_earphone_record")
+
+                    print("正在删除")
+                    return 0
                 if len(text)<16 and (text.find("再见") != -1 or text.find("拜拜") != -1 or text.find("关闭对话") != -1):
                     #EventMesh.publish("publish_AI_btnInfo",{"func":self.Close}) 
                     if dev_type != "7PIN" and dev_type != "7PIN_coze":#柒牌
@@ -4728,7 +4757,7 @@ class AI_VC(Abstract):
         if self.VC_mode == 0:
             self.Close()
             if dev_type == "7PIN" :
-                self.aud.aud_tone_play(10,200)#播放按键音
+                self.aud.aud_tone_play(10,400)#播放按键音
             #self.aud.aud_tone_play(10,200)#播放按键音
             self.AI_TTS_str = ""#"你好,有什么吩咐"
             self.AI_ASR_str = ""
index 6a0b088..12ebe53 100644 (file)
@@ -921,6 +921,7 @@ class sosInfoCallManager(Abstract):
         self.save_list = []
         self.call_state = 0
         self.sos_config = {}
+        self.phone110112_flag = 0
         self.phone110112 = ""
         if EventMesh.publish("get_storage_config","sos_list") != None:
             self.sos_list = EventMesh.publish("get_storage_config","sos_list")
@@ -946,7 +947,10 @@ class sosInfoCallManager(Abstract):
         # self.start_phone110112()
         pass
     def get_sos_flag(self,event,msg):
-        return self.sos_flag
+        if self.sos_flag == 1 or self.phone110112_flag == 1:
+            return 1
+        else:
+            return 0
         # import EventMesh
         # EventMesh.publish("set_sos_info_call")
     def close_call_timer(self):
@@ -955,14 +959,13 @@ class sosInfoCallManager(Abstract):
     def stop_sos_call(self,event,msg): #停止sos拨打
         EventMesh.publish("publish_AI_btnInfo",{"func":self.stop_sos_call_cb})
     def stop_sos_call_cb(self):
-        if self.sos_flag  == 0:
+        if self.sos_flag == 0 or self.phone110112_flag == 0:
             return
+        self.phone110112_flag=0
         self.sos_flag = 0
-        self.num = 0
         self.call_state = 0
         self.num=0 #不管有没有拨打sos都清除
         self.num_len = 0
-        self.sos_flag = 0
         self.sos_timer2.stop()
         self.sos_timer1.stop()
         voiceCall.callEnd() #挂断
@@ -970,20 +973,29 @@ class sosInfoCallManager(Abstract):
         pass
     def start_phone110112(self):
         print("start_phone110112:{} self.sos_config:{}".format(self.call_state,self.sos_config))
-        if self.call_state == 0:
-            if self.sos_config != {}:
-                if "enableSos" in self.sos_config:
-                    enableSos = self.sos_config["enableSos"]
-                    if enableSos == "1":
-                        if "enable110" in self.sos_config:
-                            p110 = self.sos_config["enable110"]
-                            if p110 == "0":
-
-                                self.phone110112 = "110"
-                                self.sos_timer1.start(2000, 0, self.phone110112_cb)
-                            elif p110 == "1":
-                                self.phone110112 = "112"
-                                self.sos_timer1.start(2000, 0, self.phone110112_cb)
+        if self.sos_config != {}:
+            if "enableSos" in self.sos_config:
+                enableSos = self.sos_config["enableSos"]
+                if enableSos == "1":
+                    if "enable110" in self.sos_config:
+                        p110 = self.sos_config["enable110"]
+                        if p110 == "0":
+                            self.phone110112 = "110"
+                            tts_str = "正在呼叫{}".format(self.phone110112)
+                            EventMesh.publish("stop_voice_record") #电话优先级最高
+                            EventMesh.publish("stop_AI_record")
+                            EventMesh.publish("play_tts",[tts_str,1])  #播放tts闹钟文本内容
+                            self.sos_timer1.start(2000, 0, self.phone110112_cb)
+                        elif p110 == "1":
+                            self.phone110112 = "112"
+                            tts_str = "正在呼叫{}".format(self.phone110112)
+                            EventMesh.publish("stop_voice_record") #电话优先级最高
+                            EventMesh.publish("stop_AI_record")
+                            EventMesh.publish("play_tts",[tts_str,1])  #播放tts闹钟文本内容
+                            self.sos_timer1.start(2000, 0, self.phone110112_cb)
+            
+        else:
+            return 1
 
     def sos_call_out_phone(self, msg):#电话拨出去
         if self.call_state == 0:
@@ -998,6 +1010,7 @@ class sosInfoCallManager(Abstract):
                 self.num=0 #不管有没有拨打sos都清除
                 self.num_len = 0
                 self.sos_flag = 0
+                self.phone110112_flag=0
                 return -1
             else:
                 EventMesh.publish(constants.EVENT.START_LOCATION,WEB_CMD_ENUM.POST_SOS_S_CMD) #开始AL定位
@@ -1006,9 +1019,11 @@ class sosInfoCallManager(Abstract):
             
     def phone110112_cb(self,*argc):
         if self.call_state == 0:
-            EventMesh.publish("stop_voice_record") #电话优先级最高
-            EventMesh.publish("stop_AI_record")
             ret = voiceCall.callStart(self.phone110112)
+            if ret != -1:
+                self.phone110112_flag=1
+            else:
+                self.phone110112_flag=0
             # print("ret:{} {}".format(ret,self.phone110112))
             self.phone110112 = ""
 
@@ -1020,6 +1035,13 @@ class sosInfoCallManager(Abstract):
         
         if self.call_state == 0:
             self.sos_phone_num = phonenumber
+            EventMesh.publish("stop_voice_record") #电话优先级最高
+            EventMesh.publish("stop_AI_record")
+            
+            tts_str = "正在呼叫号码{}".format(self.sos_phone_num)
+            EventMesh.publish("stop_voice_record") #电话优先级最高
+            EventMesh.publish("stop_AI_record")
+            EventMesh.publish("play_tts",[tts_str,1])  #播放tts闹钟文本内容
             self.sos_timer1.start(2000, 0, self.sos_call_out_phone)
             
             
@@ -1038,38 +1060,31 @@ class sosInfoCallManager(Abstract):
             EventMesh.publish("stop_voice_record") #电话优先级最高
             EventMesh.publish("stop_AI_record")
             EventMesh.publish("play_tts",[tts_str,1])  #播放tts闹钟文本内容
-            self.sos_flag = 0
-            self.num = 0
             self.call_state = 0
             self.num=0 #不管有没有拨打sos都清除
             self.num_len = 0
             self.sos_flag = 0
+            self.phone110112_flag=0
             return
         if self.call_state != 0:
             return
         if len(self.sos_list) > 0:
-            EventMesh.publish("stop_voice_record") #电话优先级最高
-            EventMesh.publish("stop_AI_record")
-            if self.sos_flag == 0:
-                self.sos_flag = 1
-            tts_str = "正在呼叫中"
-            EventMesh.publish("stop_voice_record") #电话优先级最高
-            EventMesh.publish("stop_AI_record")
-            EventMesh.publish("play_tts",[tts_str,1])  #播放tts闹钟文本内容
-            self.sos_timer1.start(5000, 0, self.call_sos_cb)
+            pass
+            self.call_sos_cb(1)
         else:
             tts_str = "未设置号码"
             EventMesh.publish("stop_voice_record") #电话优先级最高
             EventMesh.publish("stop_AI_record")
             EventMesh.publish("play_tts",[tts_str,1])  #播放tts闹钟文本内容
-            self.sos_flag = 0
-            self.num = 0
             self.call_state = 0
             self.num=0 #不管有没有拨打sos都清除
             self.num_len = 0
             self.sos_flag = 0
+            self.phone110112_flag=0
 
     def call_sos_cb(self,*argc):
+        if self.sos_flag == 0:
+            self.sos_flag = 1
         sos_flag = self.sos_flag
         EventMesh.debug_log('voicecall sos_flag',sos_flag)
         if sos_flag == 0 :
@@ -1095,6 +1110,7 @@ class sosInfoCallManager(Abstract):
                     self.num = 0
                     self.num_len = 0
                 else:
+                    self.phone110112_flag=0
                     EventMesh.debug_log("self.num:{} self.num_len :{}".format(self.num,self.num_len))
 
                     if len(self.sos_list) == 1: