From: dxy <1731678236qq.com> Date: Wed, 3 Sep 2025 08:19:37 +0000 (+0800) Subject: 按键音的问题 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=879eeca30e880d6d55d25207e6f8d92a0185ca00;p=mirrors%2FASR1603_G5.git 按键音的问题 --- diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py index 1e93caf5..a8770819 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/ai_VC.py @@ -887,6 +887,8 @@ class AI_dev(Abstract): utime.sleep_ms(500) self.KeyAI_timer = osTimer() self.KeySOS_timer = osTimer() + self.play_imei_timer = osTimer() + self.play_imei_timer_count=0 self.KeySOS_timer_count = 0 self.KeySOS_timer_flag = 0 if dev_type == "G10" : @@ -1223,15 +1225,16 @@ class AI_dev(Abstract): if self.KeyAI_press == 0 : if EventMesh.publish("get_play_new_voice_state") == 1: EventMesh.publish("set_play_new_voice_state",0) - EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠 + + EventMesh.publish("set_VC_stop_play_audio_flag",0)#按键按下不允许播放之前下发的音频数据 self.extint_AI.disable() self.KeyAI_press = 1 self.KeyAI_long_press = 0 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,400)#播放按键音 + + EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_key_press}) except Exception as e: usys.print_exception(e) @@ -1266,6 +1269,7 @@ class AI_dev(Abstract): EventMesh.publish("open_led_red") utime.sleep_ms(2000) self.aud.stopPlayStream() + print("stopAll:8") self.aud.stopAll() Power.powerDown() if self.KeyAI_status == 1:#松开 @@ -1302,7 +1306,11 @@ class AI_dev(Abstract): usys.print_exception(e) def AI_key_press(self): - EventMesh.publish("wakeup_BT") + # EventMesh.publish("wakeup_BT") + EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠 + # if dev_type == "7PIN" or dev_type == "7PIN_coze" : + # # self.aud.aud_tone_play(10,60)#播放按键音 + # EventMesh.publish("audio_montage_play",["chenggong.mp3"]) self.check_rest_timer_count = 0 print("AI_key_press") EventMesh.publish("AI_key_press") @@ -1442,8 +1450,12 @@ class AI_dev(Abstract): str_data = str_data[:-1] print("audio_montage_play:{}".format(str_data)) self.aud.montage_play('U:/static/audio.bin',1,1,str_data) + self.play_imei_timer_count=1 + self.play_imei_timer.stop() + self.play_imei_timer.start(1000,1,self.play_imei_timer_cb) def paly_iccid_imei(self,event,msg): + self.wakeup_BT() str_data = 'mp3files={}.mp3+'.format(audio_buf.index("liuliangtishi"))#流量提示 imei = modem.getDevImei() @@ -1462,6 +1474,20 @@ class AI_dev(Abstract): audio_buf.index("R_READ_TIME_{}".format(iccid[16])),audio_buf.index("R_READ_TIME_{}".format(iccid[17])),audio_buf.index("R_READ_TIME_{}".format(iccid[18])),audio_buf.index("R_READ_TIME_{}".format(iccid[19]))) str_data += '{}.mp3+'.format(audio_buf.index("shouhou"))#可联系售后解决,联系方式见售后客服电话是400-886-8777或到微信公众号柒牌SEVENBRAND自行充值: self.aud.montage_play('U:/static/audio.bin',1,1,str_data) + #开定时器不让系统休眠 + self.play_imei_timer_count=1 + self.play_imei_timer.stop() + self.play_imei_timer.start(1000,1,self.play_imei_timer_cb) + + def play_imei_timer_cb(self,event=None,msg=None): + if self.play_imei_timer_count == 1: + if EventMesh.publish("get_audio_play_state") == 0: + print("音频文件播放完成") + self.play_imei_timer_count=0 + self.play_imei_timer.stop() + return + EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠 + #鉴权出错,播放imei号 def paly_device_res_error(self,event,msg): self.wakeup_BT() @@ -1476,6 +1502,9 @@ class AI_dev(Abstract): audio_buf.index("R_READ_TIME_{}".format(imei[12])),audio_buf.index("R_READ_TIME_{}".format(imei[13])),audio_buf.index("R_READ_TIME_{}".format(imei[14]))) #print("str_data:{}".format(str_data)) self.aud.montage_play('U:/static/audio.bin',1,1,str_data) + self.play_imei_timer_count=1 + self.play_imei_timer.stop() + self.play_imei_timer.start(1000,1,self.play_imei_timer_cb) #存储信息 class getStorageDataManager(Abstract):#获取内存数据 @@ -2688,6 +2717,11 @@ class AI_VC(Abstract): 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.subscribe("SET_TTS_VOLUME", self.set_tts_volume) + EventMesh.subscribe("set_VC_stop_play_audio_flag", self.set_VC_stop_play_audio_flag) + EventMesh.subscribe("set_yuyinaudio_flag",self.set_yuyinaudio_flag) + EventMesh.subscribe("get_audio_play_state",self.get_audio_play_state) + # EventMesh.subscribe("chenggong_tone",self.chenggong_tone) + pass EventMesh.publish("close_led") self.dialog_attributes_provider = EventMesh.publish("get_storage_config","dialog_attributes_provider")#智能体类型配置 @@ -2748,6 +2782,9 @@ class AI_VC(Abstract): except Exception as e: usys.print_exception(e) + def set_VC_stop_play_audio_flag(self,event = None, msg = None): + self.VC_stop_play_audio_flag = msg + print("self.VC_stop_play_audio_flag:{}".format(self.VC_stop_play_audio_flag)) def audio_test(self,event = None, msg = None): self.VC_Speech_Start() @@ -2890,22 +2927,29 @@ class AI_VC(Abstract): else: self.aud.setVolume(self.VC_TTS_volume //10) pass + def set_yuyinaudio_flag(self, event=None, msg = None): + self.voice_flag=0 + def get_audio_play_state(self, event=None, msg = None): + return self.audio_play_state + def AI_key_press(self, event=None, msg = None):#按键按下 EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠 + if EventMesh.publish("get_sos_flag")== 1: + return 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: - 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.chenggong_tone() #self.aud.aud_tone_play(10,200)#播放按键音 self.AI_TTS_str = ""#"你好,有什么吩咐" self.AI_ASR_str = "" @@ -2921,8 +2965,7 @@ class AI_VC(Abstract): self.AI_VC_start() - # if dev_type != "7PIN": - # self.chenggong_tone() + # self.Close() # self.AI_VC_start() self.AI_key_long_press_flag = 0 @@ -3117,10 +3160,11 @@ class AI_VC(Abstract): utime.sleep_ms(1) self.VC_record_thread_lock = 0 print("VC_record_thread_thread_close") - try: - _thread.stop_thread(self.VC_record_thread_id) - except Exception as e: - usys.print_exception(e) + if self.VC_record_thread_id != 0: + try: + _thread.stop_thread(self.VC_record_thread_id) + except Exception as e: + usys.print_exception(e) self.VC_record_thread_id = 0 #获取录音数据 @@ -3420,7 +3464,7 @@ class AI_VC(Abstract): self.AI_TTS_str = TTS_str EventMesh.publish("publish_AI_btnInfo",{"func":self.AI_VC_start}) self.Close_flag = 1 - print("websocket_error2") + print("websocket_error2{}".format(self.websocket_error_count)) print("websocket_error4") @@ -3493,10 +3537,11 @@ class AI_VC(Abstract): self.AI_VC_send_data_queue.clear() self.AI_VC_send_data_queue_thread_lock = 0 print("AI_VC_send_data_queue_thread_close") - try: - _thread.stop_thread(self.AI_VC_send_data_queue_thread_id) - except Exception as e: - usys.print_exception(e) + if self.AI_VC_send_data_queue_thread_id != 0: + try: + _thread.stop_thread(self.AI_VC_send_data_queue_thread_id) + except Exception as e: + usys.print_exception(e) self.AI_VC_send_data_queue_thread_id = 0 #发送数据队列 def AI_VC_send_data_queue_thread(self): @@ -3576,10 +3621,11 @@ class AI_VC(Abstract): utime.sleep_ms(1) self.AI_client_VC_recv_lock = 0 print("AI_client_VC_recv_thread_close") - try: - _thread.stop_thread(self.AI_client_VC_recv_id) - except Exception as e: - usys.print_exception(e) + if self.AI_client_VC_recv_id!= 0: + try: + _thread.stop_thread(self.AI_client_VC_recv_id) + except Exception as e: + usys.print_exception(e) self.AI_client_VC_recv_id = 0 #Ai VC websocket返回数据 def AI_client_VC_recv(self,cli): @@ -3793,7 +3839,9 @@ class AI_VC(Abstract): EventMesh.publish("open_led_green")#绿色 - + if self.VC_stop_play_audio_flag == 0: + print("新的AI对话不允许以前的播放数据:") + break print("下发音频数据1:{}".format(len(recv_data))) if self.play_data_save_flag == 1: @@ -3847,6 +3895,7 @@ class AI_VC(Abstract): print("AI_client_VC_recv END!!!!!!!!!!!!!!!!!!!!!!!!!!!") def put_record_data(self,data): + #print("下发音频数据1:{}".format(len(data[0]))) ret=self.AI_audio_queue.put(data) self.tts_in_data_len += len(data[0]) @@ -4423,7 +4472,7 @@ class AI_VC(Abstract): return 0 - if text.find("解绑设备") != -1 or text.find("设备解绑") != -1: + if text.find("确认解绑设备") != -1 or text.find("确认设备解绑") != -1: self.AI_TTS_str = "设备解绑中...." self.Close_flag = 1 EventMesh.publish("send_unbind_dev_to_iot") @@ -4615,6 +4664,7 @@ class AI_VC(Abstract): #VC开始 def AI_VC_start(self): print("AI_VC_start1") + EventMesh.publish(constants.EVENT.SYSTEM_UP)#唤醒休眠 self.VC_satrt_flag = 1 self.VC_stop_play_audio_flag = 1 @@ -4623,7 +4673,7 @@ class AI_VC(Abstract): self.VC_Thinking_timerout = 0 EventMesh.publish("open_led_all") EventMesh.publish("wakeup_BT") - self.VC_Play_End()#关闭音频播放 + #self.VC_Play_End()#关闭音频播放 print("AI_VC_start2") #self.aud.aud_tone_play(16,200)#播放按键音 self.LocalRespondingEnded_timerout = 0 @@ -4639,8 +4689,10 @@ class AI_VC(Abstract): print("self.VC_state :{}".format(self.VC_state )) EventMesh.publish("system_sleep_rest")#防止黑屏 if self.AI_client_VC_isconnect == 0: - self.Close() + #self.Close() return + # self.aud.stopPlayStream() + # self.aud.stopAll() self.AI_client_VC_start_requset() print("AI_VC_start3") @@ -5038,10 +5090,11 @@ class AI_VC(Abstract): utime.sleep_ms(1) self.AI_audio_queue_thread_lock = 0 print("AI_audio_queue_thread_close2!!!!!!!!!!!!!!!!!") - try: - _thread.stop_thread(self.AI_audio_queue_thread_id) - except Exception as e: - usys.print_exception(e) + if self.AI_audio_queue_thread_id != 0: + try: + _thread.stop_thread(self.AI_audio_queue_thread_id) + except Exception as e: + usys.print_exception(e) self.AI_audio_queue_thread_id = 0 # 音频队列 def AI_audio_queue_thread(self): @@ -5128,7 +5181,8 @@ class AI_VC(Abstract): print("AI_audio_queue_thread:ERROR:") usys.print_exception(e) self.AI_audio_queue_thread_lock = 0 - #print("AI_audio_queue_thread:exit") + self.AI_audio_queue_thread_id = 0 + print("AI_audio_queue_thread:exit") def factory_mode(self): print("factory_mode") EventMesh.publish("publish_AI_btnInfo",{"func":self.Close}) @@ -5171,7 +5225,7 @@ class AI_VC(Abstract): self.VC_Speech_End() print("ai_VC Close1.1!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") - self.VC_init() + print("ai_VC Close1.2!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!") try: @@ -5207,6 +5261,7 @@ class AI_VC(Abstract): self.AI_ASR_send_buf_len = 0 #self.AI_WS_connect_Queue.put(self.AI_client_VC) EventMesh.publish("close_led") + self.VC_init() self.VC_satrt_flag = 0 # try: # while True: diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py index 8f93d900..51fdf90f 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/protocol.py @@ -387,7 +387,7 @@ class IOTWebLocationManager(Abstract): # self.timer_read_GPS_info.stop() if self.location_queue.empty() == False: self.location_queue.clear() - if self.location_thread_id == 1: + if self.location_thread_id != 0: try: _thread.stop_thread(self.location_thread_id) except Exception as e: @@ -1234,7 +1234,7 @@ class SockMangager(Abstract): def __init__(self): self.thread_buf_size = 16*1024 self.iot_web_send_queue = Queue(100) - self.iot_web_protoclo_recv_id=None + self.iot_web_protoclo_recv_id=0 self.iot_protocol_client = None self.connect_web_timer = osTimer() self.connect_web_timer_count = 0 @@ -1246,7 +1246,7 @@ class SockMangager(Abstract): self.vbat_buf = [] self.network_state = 0 self.curr_battery_level = 0 - self.socket_send_queue_id = None + self.iot_web_send_queue_id = 0 self.bat_count = 0 self.minute_now_old = 0 self.old_minute = 0 @@ -1667,15 +1667,17 @@ class SockMangager(Abstract): url_t = "ws://220.160.104.34:30800/ws-hub/dev/v1?qp-dt={}".format(token) try: self.iot_protocol_client=uwebsocket.Client.connect(url_t, debug=True) + self.reconnect_count=0 except Exception as e: print("再次连接") - self.iot_protocol_client=uwebsocket.Client.connect(url_t, debug=True) - + self.reconnect_count+=1 + EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) #self.connect_iot_websocket() + return if self.iot_protocol_client != None: self.reconnect_count = 0 _thread.stack_size(self.thread_buf_size+8*1024) #_thread.stack_size(16*1024) - self.socket_send_queue_id = _thread.start_new_thread(self.socket_send_queue_thread, ()) + self.iot_web_send_queue_id = _thread.start_new_thread(self.socket_send_queue_thread, ()) _thread.stack_size(8*1024) _thread.stack_size(self.thread_buf_size+8*1024) @@ -1752,6 +1754,8 @@ class SockMangager(Abstract): # EventMesh.publish("connect_iot_websocket_cb") EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) break + elif recv_data == "": + print("下发的空数据 不做处理") else: if len(recv_data) != 0: self.reconnect_count = 0 @@ -1762,26 +1766,27 @@ class SockMangager(Abstract): # EventMesh.publish("connect_iot_websocket_cb") EventMesh.publish("publish_AI_btnInfo",{"func":self.connect_iot_websocket}) break - self.iot_web_protoclo_recv_id =None + self.iot_web_protoclo_recv_id =0 def iot_web_send_queue_close(self): - if self.socket_send_queue_id != None: + if self.iot_web_send_queue_id != 0: if self.iot_web_send_queue.empty()!=True: self.iot_web_send_queue.clear() + try: - _thread.stop_thread(self.socket_send_queue_id) + _thread.stop_thread(self.iot_web_send_queue_id) except Exception as e: - print("iot_web_protoclo_recv_id !!!!!!!!") - print("iot_web_protoclo_recv_id 1111!!!!!!!!") - self.socket_send_queue_id = None + print("iot_web_send_queue_close !!!!!!!!") + print("iot_web_send_queue_close 1111!!!!!!!!") + self.iot_web_send_queue_id = 0 def iot_web_protoclo_recv_close_therad(self): - if self.iot_web_protoclo_recv_id != None: + if self.iot_web_protoclo_recv_id != 0: try: _thread.stop_thread(self.iot_web_protoclo_recv_id) except Exception as e: print("self.iot_web_protoclo_recv_id !!!!!!!!") - self.iot_web_protoclo_recv_id = None + self.iot_web_protoclo_recv_id = 0 if self.iot_protocol_client != None: try: print("关闭websocke") @@ -1953,7 +1958,7 @@ class IOTWeb_post_bt_connect_restProtoCol(ProtoCol): def recv(self, event, msg): """ - @param event: 心跳成功 + @param event: 上报蓝牙耳机连接状态 @param msg: 接收到的下行数据 """ print("recv post_bt_connect_rest{}".format(msg)) @@ -1985,7 +1990,7 @@ class IOTWeb_fence_sosProtoCol(ProtoCol): def recv(self, event, msg): """ - @param event: 心跳成功 + @param event: 电子围栏警告 @param msg: 接收到的下行数据 """ EventMesh.publish(WEB_CMD_ENUM.FENCE_SOS_S) @@ -2439,7 +2444,7 @@ class IOTWeb_sos_listProtoCol(ProtoCol): print(read_soslist) EventMesh.publish(WEB_CMD_ENUM.SOS_LIST_S_CMD) -#闹钟铃声下发 +#音量下发 class IOTWeb_volumeProtoCol(ProtoCol): """volume""" TYPE = "volume" @@ -2639,6 +2644,7 @@ class IOTWeb_voice_recordProtoCol(ProtoCol): get_sos_flag = EventMesh.publish("get_sos_flag") if get_sos_flag != 0: s_rest = "0" + print("正在电话") EventMesh.publish(WEB_CMD_ENUM.VOICE_RECORD_S_CMD,s_rest) return record_mode = EventMesh.publish("get_voice_record_mode") @@ -2718,6 +2724,13 @@ class IOTWeb_unbind_devProtoCol(ProtoCol): EventMesh.publish("set_storage_config",["switch_bt_state","1"]) EventMesh.publish("send_bt_switch_toble","1") EventMesh.publish("play_tts",[play_str,1]) + # ret = 0 + # ret = ql_fs.path_exists("/usr/static/storage_file")#配置文件 + # if ret == True: + # ql_fs.rmdirs("/usr/static/storage_file") + # ql_fs.mkdirs("/usr/static/storage_file") + # utime.sleep_ms(2000) + # Power.powerRestart() pass else: play_str = "设备解绑失败" @@ -2772,6 +2785,13 @@ class IOTWeb_user_unbind_devProtoCol(ProtoCol): EventMesh.publish("set_storage_config",["switch_bt_state","1"]) EventMesh.publish("send_bt_switch_toble","1") EventMesh.publish(WEB_CMD_ENUM.USER_UNBIND_DEV_S) + # ret = 0 + # ret = ql_fs.path_exists("/usr/static/storage_file")#配置文件 + # if ret == True: + # ql_fs.rmdirs("/usr/static/storage_file") + # ql_fs.mkdirs("/usr/static/storage_file") + # utime.sleep_ms(100) + # Power.powerRestart() print("recv user_unbind_dev{}".format(msg)) #下发位子留言 class IOTWeb_text_msgProtoCol(ProtoCol): @@ -2987,7 +3007,7 @@ class IOTWeb_scheduleProtoCol(ProtoCol): EventMesh.publish("set_schedule_info",schedule)# print(schedule) EventMesh.publish(WEB_CMD_ENUM.SCHEDULE_S_CMD) -# +#下发新的语音未读留言 class IOTWeb_new_voice_msgProtoCol(ProtoCol): """new_voice_msg""" TYPE = "new_voice_msg" @@ -3021,7 +3041,7 @@ class IOTWeb_new_voice_msgProtoCol(ProtoCol): EventMesh.publish(WEB_CMD_ENUM.NEW_VOICE_MSG_S) print("recv new_voice_msg{}".format(msg)) - +#请求未读的语音消息列表 class IOTWeb_get_new_voice_msgProtoCol(ProtoCol): """get_new_voice_msg""" TYPE = "get_new_voice_msg" @@ -3203,7 +3223,7 @@ class IOTWeb_put_voice_msg_stateProtoCol(ProtoCol): @param msg: 接收到的下行数据 """ print("recv put_voice_msg_state{}".format(msg)) - +#收到蓝牙连接记录获取请求 class IOTWeb_get_bt_connect_record_listProtoCol(ProtoCol): """get_bt_connect_record_list""" TYPE = "get_bt_connect_record_list" diff --git a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py index 518fb130..88100594 100644 --- a/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py +++ b/2.sdk/project/7PIN_1_5/sdk/services/microPython/ports/quectel/core/voice_record.py @@ -184,19 +184,27 @@ class VOICE_RECORD(Abstract): #静默录音 try: #发送静默录音数据到iot平台 if self.voice_mode == 1: #静默录音开始发送 + get_sos_flag = EventMesh.publish("get_sos_flag") + if get_sos_flag != 0: + print("打电话退出静默录音") + EventMesh.publish("SEND_JINMOAUDIO_TO_IOT",[read_buf,self.msgid_int,0]) + break EventMesh.publish("SEND_JINMOAUDIO_TO_IOT",[read_buf,self.msgid_int,self.start_voice_record_flag]) pass elif self.voice_mode == 2: #语音留言开始 - pass + get_sos_flag = EventMesh.publish("get_sos_flag") + if get_sos_flag != 0: + print("打电话退出语音留言") + # EventMesh.publish("set_yuyinaudio_flag") + + EventMesh.publish("SEND_YUYINAUDIO_TO_IOT",[read_buf,self.msgid_int,0]) + break EventMesh.publish("SEND_YUYINAUDIO_TO_IOT",[read_buf,self.msgid_int,self.start_voice_record_flag]) if self.start_voice_record_flag == 0: 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)