更新设置太低音量没有声音的问题
authordxy <1731678236qq.com>
Mon, 1 Sep 2025 10:14:04 +0000 (18:14 +0800)
committerdxy <1731678236qq.com>
Mon, 1 Sep 2025 10:14:04 +0000 (18:14 +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
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py

index 548633e..5f78204 100644 (file)
@@ -287,6 +287,36 @@ class AI_UART():
         if self.uart_timer_count >200:
             self.read_uart_data = ""
             self.uart_timer.stop()
+    def split_combined_json(self,combined_str):
+        """
+        将连续的JSON字符串分割为多个独立的JSON字符串列表
+        
+        参数:
+            combined_str: 多个JSON拼接的字符串
+        返回:
+            分割后的
+        """
+        json_list = []
+        start_index = 0
+        brace_count = 0  # 用于匹配{}括号
+        print("combined_str:{}".format(combined_str))
+        for i, char in enumerate(combined_str):
+            if char == '{':
+                brace_count += 1
+            elif char == '}':
+                brace_count -= 1
+                
+                # 当括号完全匹配(count=0)时,说明一个完整的JSON对象结束
+                if brace_count == 0:
+                    # 提取从start_index到当前位置的子串(包含当前})
+                    json_str = combined_str[start_index:i+1].strip()
+                    if json_str:  # 避免空字符串
+                        json_list.append(json_str)
+                    start_index = i + 1  # 下一个JSON的起始位置
+        print("json_list{}".format(json_list))
+        
+        return json_list
+    
     def uart_call(self,para):
         EventMesh.publish("publish_AI_btnInfo",{"func":self.pares_uart_data})
         #print("ai_uart:{}".format(para))  
@@ -299,6 +329,7 @@ class AI_UART():
         uart_data_str = uart_data.decode('utf-8')
         self.read_uart_data = self.read_uart_data +uart_data_str
         try:
+
             ujson.loads(self.read_uart_data)
         except Exception as e:
             print("json数据不完整:self.read_uart_data{}".format(self.read_uart_data))
@@ -307,6 +338,29 @@ class AI_UART():
         self.uart_timer.stop()
         self.uart_timer_count = 0
         self.playload_data(self.read_uart_data)
+
+        # 分割JSON
+        # json_strings = self.split_combined_json(uart_data_str)
+        
+        # # 逐个解析并处理
+        # for i, json_str in enumerate(json_strings, 1):
+        #     print("第{}个JSON{}".format(i,json_str))
+        #     try:
+        #         data = ujson.loads(json_str)
+             
+        #         # 在这里添加你的业务逻辑,比如根据event处理不同事件
+        #         self.uart_timer.stop()
+        #         self.uart_timer_count = 0
+        #         self.playload_data(self.read_uart_data)
+        #         # if data.get("event") == "bt_connect_single":
+                    
+        #         # elif data.get("event") == "bt_scan_rest":
+                    
+        #     except Exception as e:
+        #         print("JSON解析错误:原始字符串:")
+        #     print("-" * 50)
+
+        
         
         # print("uart_data_str:{}",uart_data_str)
         # if len(uart_data_str) < (HEARDER+1+1):
@@ -413,11 +467,13 @@ class AI_UART():
         print("clear_earphone_record{}".format(json_str))
         self.send_data(json_str)
     def adjust_volume_toBle(self,event,msg): #
-
+        volume = int(msg)
+        if volume <= 10:
+            volume = 10
         json_data = \
         {
             "event": "adjust_volume",
-            "data":str(msg)
+            "data":str(volume)
         }
         json_str  =ujson.dumps(json_data)
         print("adjust_volume_toBle{}".format(json_str))
@@ -2823,7 +2879,11 @@ class AI_VC(Abstract):
         EventMesh.publish("set_storage_config",["VC_TTS_volume",msg])#音量配置
         self.VC_TTS_volume = msg
         print("set_tts_volume:{} {}".format(self.VC_TTS_volume,msg))
-        self.aud.setVolume(self.VC_TTS_volume //10)
+        if int(msg) <= 10:  #最小一定要设置1要不然没有声音
+            volume = 10 //10
+            self.aud.setVolume(volume)
+        else:
+            self.aud.setVolume(self.VC_TTS_volume //10)
         pass
     def AI_key_press(self, event=None, msg = None):#按键按下
         EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠
index 9bb0fa8..8f93d90 100644 (file)
@@ -970,7 +970,6 @@ class sosInfoCallManager(Abstract):
         self.sos_timer1.stop()
         voiceCall.callEnd() #挂断
 
-        pass
     def start_phone110112(self):
         print("start_phone110112:{} self.sos_config:{}".format(self.call_state,self.sos_config))
         if self.sos_config != {}:
@@ -2207,7 +2206,7 @@ class IOTWeb_FindDeviceProtoCol(ProtoCol):
         @param event:定位信息下发
         @param msg: 接收到的下行数据
         """
-        alarm_TTS_str="在这呢"
+        alarm_TTS_str="我在这呢"
         base_sentence = "{}".format(alarm_TTS_str)
         repeat_sentence = (base_sentence + ",") * 3  # 重复5次并加逗号分隔
         final_sentence = repeat_sentence.rstrip(",")
@@ -2474,6 +2473,7 @@ class IOTWeb_volumeProtoCol(ProtoCol):
         if "data" in msg:
             r_volume = msg["data"]
             print("recv volume{} type:{}".format(r_volume,type(msg)))
+            
             EventMesh.publish("SET_TTS_VOLUME",int(r_volume))
             EventMesh.publish("adjust_volume_toBle",r_volume)
         EventMesh.publish(WEB_CMD_ENUM.VOLUME_S_CMD)
@@ -2636,13 +2636,18 @@ class IOTWeb_voice_recordProtoCol(ProtoCol):
                 
             elif data == "1":
                 
-                
+                get_sos_flag = EventMesh.publish("get_sos_flag") 
+                if get_sos_flag != 0:
+                    s_rest = "0"
+                    EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest)
+                    return
                 record_mode = EventMesh.publish("get_voice_record_mode")
                 if record_mode == None:
                     record_mode = 0
                 get_VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")
                 if get_VC_satrt_flag == None:
                     get_VC_satrt_flag = 0
+                
                 if record_mode == 2 or get_VC_satrt_flag == 1:# 如果在AI对话 或者语音留言不允许静默录音
                     s_rest = "0"
                     EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest)
index 385aa4b..518fb13 100644 (file)
@@ -193,6 +193,10 @@ class VOICE_RECORD(Abstract): #静默录音
                             break
                     except Exception as e:
                         usys.print_exception(e)
+                    get_sos_flag = EventMesh.publish("get_sos_flag") 
+                    if get_sos_flag != 0:
+                        EventMesh.publish("stop_voice_record")
+                        break
                     # print("voice Record_len:{}".format(Record_len))
             except Exception as e:
                 usys.print_exception(e)