From: azao <821478748@qq.com> Date: Tue, 4 Nov 2025 04:06:37 +0000 (+0800) Subject: NLP实现,柒牌1.5代新功能已基本实现 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=0a208ddfce322f522faf8d76f5edf07e1ce647c6;p=mirrors%2FASR1603_G5.git NLP实现,柒牌1.5代新功能已基本实现 --- 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 5f5e0e85..1bb95132 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 @@ -2518,6 +2518,7 @@ class AI_VC(Abstract): EventMesh.subscribe("change_volume",self.change_volume) EventMesh.subscribe("find_cmd",self.find_cmd) #查询命令 EventMesh.subscribe("change_voice",self.change_voice) #改变音色 + EventMesh.subscribe("Close_VC",self.Close_VC) #外部结束对话 self.voice_timer = osTimer()#语音留言10S按下按键确定是否播放的判断定时器 self.voice_cnt = 0 #留言定时器计数 self.voicerupt_flag = 0#留言选择按键接听标志位 @@ -3178,12 +3179,14 @@ class AI_VC(Abstract): pass 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翻译模式 + EventMesh.publish("send_trans_end_flag_to_iot")#退出翻译 self.trans_flag=0 EventMesh.publish("stop_voice_record") #关闭语音录音 exit_tts ="已退出AI翻译模式" @@ -4761,11 +4764,11 @@ class AI_VC(Abstract): return 1 if text.find("查询") != -1: - if text.find("信号") != -1 : - signal = net.csqQueryPoll() + # if text.find("信号") != -1 : + # signal = net.csqQueryPoll() - self.AI_TTS_str = "当前信号{}".format(signal) - return 0 + # self.AI_TTS_str = "当前信号{}".format(signal) + # return 0 if text.find("电量") != -1 : battery = EventMesh.publish("get_battery") print("电量查询:{}".format(battery)) @@ -4780,14 +4783,14 @@ class AI_VC(Abstract): self.AI_TTS_str = "当前电池电压{}".format(Vbatt) return 0 - if text.find("卡号") != -1 : - iccid = sim.getIccid() - if iccid != -1 and len(iccid) > 5: - print("iccid{}".format(iccid)) - self.AI_TTS_str = "当前卡号为:{}".format(iccid) - else: - self.AI_TTS_str = "卡号查询失败" - return 0 + # if text.find("卡号") != -1 : + # iccid = sim.getIccid() + # if iccid != -1 and len(iccid) > 5: + # print("iccid{}".format(iccid)) + # self.AI_TTS_str = "当前卡号为:{}".format(iccid) + # else: + # self.AI_TTS_str = "卡号查询失败" + # return 0 if text.find("设备号") != -1 : imei = modem.getDevImei() if imei != -1 and len(imei) > 5: @@ -5486,13 +5489,33 @@ class AI_VC(Abstract): EventMesh.publish("post_device_state") EventMesh.publish("adjust_volume_toBle",self.VC_TTS_volume) self.AI_TTS_str = "好嘞,音量已经调大了,当前音量是{}".format(self.VC_TTS_volume) + elif msg >= 100:#修改为具体音量 + if msg > 200: + self.VC_TTS_volume = 100 + self.AI_TTS_str = "音量已设为最大" + else: + self.VC_TTS_volume = msg - 100#还原数据 + self.aud.setVolume(self.VC_TTS_volume //10) + EventMesh.publish("set_storage_config",["VC_TTS_volume",self.VC_TTS_volume]) + EventMesh.publish("post_device_state") + EventMesh.publish("adjust_volume_toBle",self.VC_TTS_volume) + self.AI_TTS_str = "好嘞,音量已经调节了,当前音量是{}".format(self.VC_TTS_volume) #查询指令判断 def find_cmd(self,event ,msg): if "电量" in msg: battery = EventMesh.publish("get_battery") print("电量查询:{}".format(battery)) - tts_play_str = "电量剩余百分之{}".format(battery) - EventMesh.publish("play_tts",[tts_play_str,0]) + self.AI_TTS_str = "电量剩余百分之{}.format(battery)" + elif "信号" in msg: + signal = net.csqQueryPoll() + self.AI_TTS_str = "当前信号{}".format(signal) + elif "卡号" in msg: + iccid = sim.getIccid() + if iccid != -1 and len(iccid) > 5: + print("iccid{}".format(iccid)) + self.AI_TTS_str = "当前卡号为:{}".format(iccid) + else: + self.AI_TTS_str = "卡号查询失败" #改变音色判断 def change_voice(self,event ,msg): voice = msg @@ -5769,7 +5792,8 @@ class AI_VC(Abstract): print("factory_timer_cb play......") #self.aud.play(1,0,'U:/static/peizhichenggong.mp3')#切换成功 EventMesh.publish("audio_montage_play",["xinhaoruo1.mp3"]) - + def Close_VC(self,event,msg): + EventMesh.publish("publish_AI_btnInfo",{"func":self.Close}) def Close(self): self.VC_stop_play_audio_flag = 0 self.VC_Thinking_timerout = 0 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 75a413b0..5e1f91ba 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 @@ -1352,6 +1352,7 @@ class SockMangager(Abstract): EventMesh.subscribe("send_trans_come_flag_to_iot",self.send_trans_come_flag_to_iot)#进入翻译 EventMesh.subscribe("send_trans_ok_flag_to_iot",self.send_trans_ok_flag_to_iot)#向APP发送进入翻译成功 + EventMesh.subscribe("send_trans_end_flag_to_iot",self.send_trans_end_flag_to_iot)#退出翻译 # import EventMesh # EventMesh.publish("play_new_voice_list") EventMesh.subscribe("play_new_voice_list",self.play_new_voice_list) #播放语音未读信息 @@ -1668,6 +1669,18 @@ class SockMangager(Abstract): send_data = protocol_send_total_data(trans_ok) EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data) pass + + def send_trans_end_flag_to_iot(self,event,msg): #退出翻译上报到IOT平台 + time_tmp = utime.mktime(date_tmp) + trans_open = { + "msg": "退出翻译", + "data": None, + "cmd": "translate_device_exit", + "ts": time_tmp + } + send_data = protocol_send_total_data(trans_open) + EventMesh.publish("CHANNEL_IOT_WEB_SEND",send_data) + pass def send_jm_audio_to_iot(self,event,msg): #静默录音音频数据上报到IOT平台 send_data = b'' @@ -2579,16 +2592,7 @@ class IOTWeb_sos_listProtoCol(ProtoCol): #NLP指令处理 def ai_cmd_handle(cmd): # print("") - if "音量" in cmd:#当指令中有音量时,截取音量操作 - voice_start_index = cmd.index("音量") + len("音量")#动态判断截取部分 - volume = cmd[voice_start_index:]#音量截取 - if volume == "加大": - EventMesh.publish("change_volume",1) - elif volume == "减小": - EventMesh.publish("change_volume",0) - tts_play_str = "音量已经" + volume - EventMesh.publish("play_tts",[tts_play_str,0]) - elif "查询" in cmd:#当指令中有查询时,截取查询操作 + if "查询" in cmd:#当指令中有查询时,截取查询操作 voice_start_index = cmd.index("查询") + len("查询")#动态判断截取部分 find = cmd[:voice_start_index]#查询截取 EventMesh.publish("find_cmd",find) @@ -2604,13 +2608,33 @@ def ai_cmd_handle(cmd): tts_play_str = "语速已经" + volume EventMesh.publish("play_tts",[tts_play_str,0]) elif "会议纪要" in cmd:#当指令中有会议纪要时,进入会议纪要模式 + print("cmd:已进入会议") EventMesh.publish("come_meet_mode")#进入会议纪要 elif "翻译" in cmd:#当指令中有翻译时,进入AI翻译模式 + print("cmd:已进入翻译") EventMesh.publish("come_trans_mode")#进入AI翻译纪要 elif "声音改为" in cmd:#当指令中有声音改为时,进入音色修改 voice_start_index = cmd.index("声音改为") + len("声音改为")#动态判断截取部分 find = cmd[voice_start_index:]#查询截取 EventMesh.publish("change_voice",find) + elif "结束对话" in cmd:#当指令中有结束对话时,结束当前对话 + EventMesh.publish("Close_VC") + elif "音量调节" in cmd:#当指令中有音量改为时,音量改为具体数值 + voice_start_index = cmd.index("音量调节:") + len("音量调节:")#动态判断截取部分 + find = cmd[voice_start_index:]#查询截取 + print("find = {}".format(find)) + if find == "+10": + EventMesh.publish("change_volume",1) + tts_play_str = "音量已经加大" + elif find == "-10": + EventMesh.publish("change_volume",0) + tts_play_str = "音量已经减小" + else: + volume = int(find) + volume += 100#设置音量以100-200为参数 + EventMesh.publish("change_volume",volume) + tts_play_str = "音量已经改为" + find + EventMesh.publish("play_tts",[tts_play_str,0]) #NLP指令 class IOTWeb_Nlp_ConfigProtoCol(ProtoCol):