取消开机获取语音
authorazao <821478748@qq.com>
Tue, 23 Dec 2025 08:43:21 +0000 (16:43 +0800)
committerazao <821478748@qq.com>
Thu, 25 Dec 2025 02:16:51 +0000 (10:16 +0800)
修改ota平台配置bug
更新小程序翻译模式判断
处理细节问题
添加未读播放“第n条”的提示

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/main_init.py
2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py

index 86be6fc..d42a3ce 100644 (file)
@@ -46,8 +46,8 @@ PRESS_AUDIO_MODE = 0 #是按键音 0 是使用音频文件
 #dev_type = "7PIN_BK_coze"#k扣子小瑞
 #dev_type = "7PIN_BK_EU"#英文小瑞
 #dev_type = "7PIN_coze"#柒牌扣子
-dev_type = "7PIN"#柒牌
-# dev_type = "7PIN_1_5"#柒牌1.5
+# dev_type = "7PIN"#柒牌
+dev_type = "7PIN_1_5"#柒牌1.5
 #dev_type = 'momo'#食梦貘
 #dev_type = 'sjgq'#四季甘泉
 #dev_type = 'szbst'#深圳百事通
@@ -1177,14 +1177,17 @@ class AI_dev(Abstract):
         #msg的取值是0.5,1.0,1.5,2.0
         #而语速初始值是0,范围是-50~50
         print("已进入设置速率")
+        rate = 0
         if msg == 0.5:
-            EventMesh.publish("rate_change",-50)
+            rate = -50
         elif msg == 1.0:
-            EventMesh.publish("rate_change",0)
+            rate = 0
         elif msg == 1.5:
-            EventMesh.publish("rate_change",25)
+            rate = 25
         elif msg == 2.0:
-            EventMesh.publish("rate_change",50)
+            rate = 50
+        EventMesh.publish("rate_change",rate)
+        return rate
     def btnInfo_queue_thread(self):
         while True:
             data = self.btnInfo_queue.get()
@@ -2971,6 +2974,7 @@ class AI_VC(Abstract):
         EventMesh.subscribe("exit_meet_mode",self.exit_meet_mode)#退出会议模式
         EventMesh.subscribe("come_trans_mode",self.come_trans_mode)#进入翻译模式
         EventMesh.subscribe("exit_trans_mode",self.exit_trans_mode)#退出翻译模式
+        EventMesh.subscribe("set_trans_flag",self.set_trans_flag)#设置翻译状态
         EventMesh.subscribe("get_audio_play_state",self.get_audio_play_state)
         EventMesh.subscribe("set_voicerupt_flag",self.set_voicerupt_flag)#按键中断触发留言播放
         EventMesh.subscribe("get_recv_voice",self.get_recv_voice)#获取是否收到留言
@@ -3198,7 +3202,7 @@ class AI_VC(Abstract):
                                             EventMesh.publish("set_storage_config",["inbound_attributess_provider",self.inbound_attributess_provider])
                                             print("配置inbound_attributess_provider成功")
                                         if "speech_rate" in data["data"]:
-                                            self.speech_rate = int(data["data"]["speech_rate"])
+                                            self.speech_rate = EventMesh.publish("SET_SPEECH_RATE",float(data["data"]["speech_rate"]))
                                             EventMesh.publish("set_storage_config",["speech_rate",self.speech_rate])
                                             print("配置speech_rate成功")
                                         if "emotion" in data["data"]:
@@ -3210,7 +3214,7 @@ class AI_VC(Abstract):
                                             EventMesh.publish("set_storage_config",["ota_update_notice",self.ota_update_notice])
                                             print("配置ota_update_notice成功")
                                         if "VC_TTS_volume" in data["data"]:
-                                            self.VC_TTS_volume =data["data"]["VC_TTS_volume"]
+                                            self.VC_TTS_volume =int(data["data"]["VC_TTS_volume"])
                                             EventMesh.publish("set_storage_config",["VC_TTS_volume",self.VC_TTS_volume])
                                             print("配置VC_TTS_volume成功")
                                             
@@ -3290,9 +3294,6 @@ class AI_VC(Abstract):
     def come_trans_mode(self, event=None, msg = None):
         if self.trans_flag == 0: #还是为0就提示进入AI翻译模式
             EventMesh.publish("send_trans_come_flag_to_iot")#进入翻译
-            self.trans_flag=1
-            exit_tts ="已进入AI翻译模式"
-            EventMesh.publish("play_tts",[exit_tts,1])
         pass
     def exit_trans_mode(self, event=None, msg = None):
         if self.trans_flag == 1: #还是为1就提示已退出AI翻译模式        
@@ -3302,6 +3303,8 @@ class AI_VC(Abstract):
             self.trans_flag=0
             EventMesh.publish("send_trans_end_flag_to_iot")#退出翻译
         pass
+    def set_trans_flag(self,event,msg):
+        self.trans_flag = msg
     def exit_voice_message_mode(self, event=None, msg = None):
         if self.voice_flag == 1: #还是为1就提示已退出会议纪要模式
             self.voice_flag=0
@@ -4197,10 +4200,19 @@ class AI_VC(Abstract):
                                         self.his_timer.start(1000,1,self.history_play) 
                                         self.voice_choose_flag = 1
                                     else:#等待留言
-                                        self.wait_cnt = 0
-                                        EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_synthesis})
-                                        self.wait_timer.start(1000,1,self.wait_play) 
-                                        self.voice_choose_flag = 1
+                                        if self.pwk_notice_flag == 0:
+                                            self.wait_cnt = 0
+                                            print("未听播放1")
+                                            EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_synthesis})
+                                            self.wait_timer.start(1000,1,self.wait_play) 
+                                            self.voice_choose_flag = 1
+                            
+                                        else:#已确定播放
+                                            print("未听播放2")
+                                            self.wait_cnt = 0
+                                            EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_synthesis})
+                                            self.wait_timer.start(1000,1,self.wait_single_play) 
+                                            self.voice_choose_flag = 1
                                 else:#播放正常留言
                                     EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_VC_synthesis})
                                     self.voice_cnt = 0
@@ -4364,6 +4376,8 @@ class AI_VC(Abstract):
                                 self.wait_sort = 0
                                 self.wait_first_flag = 0#让下次未读播放提示恢复
                                 self.voice_notice = 1#开启回复
+                                if self.history_voice_flag == 1 and self.wait_voice_flag == 0:
+                                    self.voice_notice = 0
                                 EventMesh.publish("set_storage_config",["is_noread_voice",0])
                                 
                             if self.voice_choose_flag == 1:#播放完语音后,有冲突的时候关闭
@@ -4515,7 +4529,7 @@ class AI_VC(Abstract):
            EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_new_voice})#播放留言
            self.his_cnt = 0
            self.his_timer.stop() 
-    #未读留言播放定时器
+    #æ\9cªè¯»ç\95\99è¨\80æ\98¯å\90¦æ\92­æ\94¾å®\9aæ\97¶å\99¨
     def wait_play(self, *args, **kwargs):
         EventMesh.publish("publish_AI_btnInfo",{"func":self.wait_play_cb})  
     def wait_play_cb(self):
@@ -4523,12 +4537,14 @@ class AI_VC(Abstract):
         if self.voicerupt_flag == 1:#按键被按下
            self.pwk_notice_flag = 1#表示进入收听未听留言
            self.AI_VC_start()
-           EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_new_voice})#播放留言
-           self.wait_cnt = 0
-           print("进入留言定时器1,留言清空!!!!!")
-           EventMesh.publish("update_play_new_voice_info")#更新已读状态
-           self.wait_timer.stop()
+           self.wait_sort = 1
+           self.AI_TTS_str = "第"+str(self.wait_sort)+"条" 
+        #    EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_new_voice})#播放留言
+        #    self.wait_cnt = 0
+        #    print("进入留言定时器1,留言清空!!!!!")
+        #    EventMesh.publish("update_play_new_voice_info")#更新已读状态
            self.voicerupt_flag = 0
+           self.wait_timer.stop()
         if self.wait_cnt > 10:#10S后退出播放,5S是为了给语音提示留时间
            self.wait_cnt = 0
            self.recv_voice = 0#进入留言定时器,留言清空
@@ -4540,6 +4556,16 @@ class AI_VC(Abstract):
               self.voice_choose_flag = 0
            print("进入留言定时器2,留言清空!!!!!")
            self.wait_timer.stop()
+    #未读留言一条条播放定时器
+    def wait_single_play(self, *args, **kwargs):
+        EventMesh.publish("publish_AI_btnInfo",{"func":self.wait_single_play_cb})  
+    def wait_single_play_cb(self):
+        self.wait_cnt += 1
+        if self.wait_cnt > 2:#2S后播放,2S是为了给语音提示留时间
+           self.AI_VC_start()
+           EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_client_new_voice})#播放留言
+           self.wait_cnt = 0
+           self.wait_timer.stop() 
     def set_voicerupt_flag(self,event,msg):#按键控制留言播放
         self.voicerupt_flag = msg
     def get_voicerupt_flag(self,event,msg):#获取按键控制留言播放状态
@@ -5881,8 +5907,9 @@ class AI_VC(Abstract):
                         tts_str = "您有" + str(self.pwk_cnt_voice) + "条未读语音留言,10秒内按下中间键可以收听"
                         EventMesh.publish("play_tts",[tts_str,1])
                 elif self.pwk_cnt_voice == 1:
-                    tts_str = "您有1条语音留言,10秒内按下中间键可以收听"
-                    EventMesh.publish("play_tts",[tts_str,1])
+                    if self.pwk_notice_flag == 0:
+                        tts_str = "您有1条语音留言,10秒内按下中间键可以收听"
+                        EventMesh.publish("play_tts",[tts_str,1])
             if is_close_VC != None:
                 self.Close_flag = is_close_VC
             if self.AI_VC_send_data_queue.empty()!=True:
@@ -5945,13 +5972,13 @@ class AI_VC(Abstract):
             is_close_VC = data[1]
             print("是否为第一次:{}".format(self.wait_first_flag))
             if self.wait_first_flag == 0:
-                tts_play_str = "您有" + str(len(EventMesh.publish("get_play_new_voice_list"))) + "条未读留言,10秒内按下中间键可以收听"
+                tts_play_str = "您有" + str(len(EventMesh.publish("get_play_new_voice_list"))) + "条未听留言,10秒内按下中间键可以收听"
                 EventMesh.publish("play_tts",[tts_play_str,1])  
                 # self.wait_first_timer.start(1000,1,self.noread_wait_vocie)
                 self.wait_first_flag = 1
-            self.wait_sort += 1
-            tts_play_str = "第"+str(self.wait_sort)+"条" 
-            EventMesh.publish("play_tts",[tts_play_str,1])
+            elif self.wait_first_flag == 1:
+                self.wait_sort += 1
+                self.AI_TTS_str = "第"+str(self.wait_sort)+"条" 
             if new_voice_url != "":
                 self.recv_voice = 1#收到留言
                 print("未读留言查看")
index a9e5773..a23aa79 100644 (file)
@@ -5,8 +5,8 @@ import machine
 import EventMesh
 import usys
 
-dev_type = "7PIN"#柒牌1代  
-# dev_type = "7PIN_1_5"#柒牌1.5代  
+# dev_type = "7PIN"#柒牌1代  
+dev_type = "7PIN_1_5"#柒牌1.5代  
 resp=bytearray(50)
 # atcmd.sendSync('AT+log=52,1\r\n',resp,'',200)
 # EventMesh.debug_log("AT+log=52,1:{}".format(resp))
@@ -249,6 +249,7 @@ def main_init():
                 pcr.add_support(pro.IOTWeb_come_transProtoCol())#接收小程序控制进入翻译
                 pcr.add_support(pro.IOTWeb_exit_transProtoCol())#接收小程序控制退出翻译
                 pcr.add_support(pro.IOTWeb_appcontrol_meetProtoCol())#接收小程序控制进入会议
+                pcr.add_support(pro.IOTWeb_translate_device_enterProtoCol())#设备判断小程序是否在线,进入/不进入翻译模式
             pcr.add_support(pro.IOTWeb_HRProtoCol())
             pcr.add_support(pro.IOTWeb_volumeProtoCol())
             pcr.add_support(pro.IOTWeb_chat_configProtoCol())
index e64e7d2..f99d853 100644 (file)
@@ -25,8 +25,8 @@ import umqtt
 import modem
 SHA256 = uhashlib.sha256
 import SecureData
-dev_type = "7PIN"#柒牌1代  
-# dev_type = "7PIN_1_5"#柒牌1.5代  
+# dev_type = "7PIN"#柒牌1代  
+dev_type = "7PIN_1_5"#柒牌1.5代  
 def server_init(server_type = None):
     #服务器选择1,防走丢,2大锤,3三基同创,4童信,5云米,6荣为 8:ds未知 dey.hinwatch. com:9968  9:183.62.239.121:31869 10:183.62.239.121:33461
     if server_type == None:
@@ -693,6 +693,7 @@ class WEB_CMD_ENUM:
 
     NLP_PLAY_R = "ai_cmd_R"
     NLP_PLAY_S = "ai_cmd_S"
+
 class IOTSendCmdManager(Abstract):
     #
     def __init__(self):
@@ -1911,11 +1912,11 @@ class SockMangager(Abstract):
                 device_state=EventMesh.publish("GET_IOT_WEB_SEND_CMD",WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD)
                 print("device_state{}".format(device_state))
                 EventMesh.publish(WEB_CMD_ENUM.POST_DEVICE_STATE_S_CMD,device_state) #上报设备状态
-                if dev_type == "7PIN_1_5":#二代开机获取留言
-                    EventMesh.publish("set_open_device",1)
-                    EventMesh.publish("set_history_voice_flag",1)
-                    EventMesh.publish("set_wait_voice_flag",1)
-                    EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S)#向IOT获取语音未读消息
+                # if dev_type == "7PIN_1_5":#二代开机获取留言
+                #     EventMesh.publish("set_open_device",1)
+                #     EventMesh.publish("set_history_voice_flag",1)
+                #     EventMesh.publish("set_wait_voice_flag",1)
+                #     EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S)#向IOT获取语音未读消息
             
         
         # http://220.160.104.34:30800/ws-bus/test/voice-record/876226211472149?state=1,
@@ -2742,7 +2743,7 @@ def ai_cmd_handle(cmd):
             tts_play_str = EventMesh.publish("NLP_set_vad_silence",0)
         EventMesh.publish("play_tts",[tts_play_str,0])
     elif "这个不支持哦,请换一个" in cmd:
-        tts_play_str = "这个不支持哦,请换一个"
+        tts_play_str = "抱歉呀,暂不支持该方言,请换一个"
         EventMesh.publish("play_tts",[tts_play_str,0])
 
 #NLP指令
@@ -2776,6 +2777,33 @@ class IOTWeb_Nlp_ConfigProtoCol(ProtoCol):
         print("提取到的AI指令为{}".format(cmdName))
         ai_cmd_handle(cmdName)
         print("recv push_music{}".format(msg))
+#设备进入翻译,小程序返回在线情况
+class IOTWeb_translate_device_enterProtoCol(ProtoCol):
+    """translate_device_enter"""
+    TYPE = "translate_device_enter"
+
+    def send(self, event, msg):
+        # print("translate_device_enter{}".format(msg))
+        # 通过websocket发送到服务器端
+        print("设备进入翻译,小程序返回在线情况")
+
+    def recv(self, event, msg):
+        """
+        @param event:上行下发translate_device_enter
+        @param msg: 接收到的下行数据
+        """
+        print("设备进入翻译获取状态:{}".format(msg["data"]["msg"]))
+        status = msg["data"]["rest"]
+        
+        if status == "success":
+           EventMesh.publish("set_trans_flag",1)#能进入AI翻译
+           exit_tts = "已进入实时翻译模式"
+           EventMesh.publish("play_tts",[exit_tts,1])
+        elif status == "error":
+           EventMesh.publish("set_trans_flag",0)#不能进入AI翻译
+           exit_tts = msg["data"]["msg"]
+           EventMesh.publish("play_tts",[exit_tts,0])
+        print("recv translate_device_enter")
 
 #接收小程序控制进入翻译
 class IOTWeb_come_transProtoCol(ProtoCol):
@@ -3585,15 +3613,20 @@ class IOTWeb_find_new_voice_msgProtoCol(ProtoCol):
         if EventMesh.publish("get_history_voice_flag") == 1:
             if len(voice_list) == 0:#为空
                 if EventMesh.publish("get_wait_voice_flag") == 0:#未听历史留言
-                    if self.has_processed_history_voice == 0:
-                        tts_play_str = "已无更多历史留言"
-                        EventMesh.publish("play_tts",[tts_play_str,0])
-                    else:
-                        self.has_processed_history_voice = 0#读完了置为0
-                        self.history_board_flag = 0#广播置为0
+                    tts_play_str = "已无更多历史留言"
+                    EventMesh.publish("play_tts",[tts_play_str,0])
                     self.history_board_flag = 0
                     self.has_processed_wait_voice = 0
                     self.wait_first_flag = 0
+                    # if self.has_processed_history_voice == 0:
+                    #     tts_play_str = "已无更多历史留言"
+                    #     EventMesh.publish("play_tts",[tts_play_str,0])
+                    # else:
+                    #     self.has_processed_history_voice = 0#读完了置为0
+                    #     self.history_board_flag = 0#广播置为0
+                    # self.history_board_flag = 0
+                    # self.has_processed_wait_voice = 0
+                    # self.wait_first_flag = 0
                 else:#等待历史留言
                     self.has_processed_wait_voice = 0
                     self.wait_first_flag = 0
@@ -3824,13 +3857,13 @@ class IOTWeb_new_voice_msg_listProtoCol(ProtoCol):
 
     def _1M_timer_cb_(self): 
         #self.iot_web_send_queue.put("ping") 
-        # get_VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")
-        # if get_VC_satrt_flag == None:
-        #     get_VC_satrt_flag = 0
-        # if get_VC_satrt_flag == 0:
+        self._1M_flag = 0
+        self._60S_voice_flag = 1
+        get_VC_satrt_flag = EventMesh.publish("get_VC_satrt_flag")
+        if get_VC_satrt_flag == None:
+            get_VC_satrt_flag = 0
+        if get_VC_satrt_flag == 0:
             print("收到多条信息,统一播放")
-            self._1M_flag = 0
-            self._60S_voice_flag = 1
             EventMesh.publish("set_history_voice_flag",1)#修改历史留言标志位
             EventMesh.publish("set_wait_voice_flag",1)#修改60S标志位
             EventMesh.publish(WEB_CMD_ENUM.GET_NEW_VOICE_MSG_S)