From: dxy15521469561 <1731678236@qq.com> Date: Thu, 4 Jul 2024 09:30:36 +0000 (+0800) Subject: W8: X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=3649ec80060824e72755ed6b0f5d927542bbd1a7;p=mirrors%2FASR1603_G5.git W8: 关闭和开启TTS播放按钮 --- diff --git a/2.sdk/project/W8/ext/static/AI/ai_result_can_bt.png b/2.sdk/project/W8/ext/static/AI/ai_result_can_bt.png deleted file mode 100644 index de9d638e..00000000 Binary files a/2.sdk/project/W8/ext/static/AI/ai_result_can_bt.png and /dev/null differ diff --git a/2.sdk/project/W8/ext/static/AI/ai_result_can_start.png b/2.sdk/project/W8/ext/static/AI/ai_result_can_start.png new file mode 100644 index 00000000..6fae0204 Binary files /dev/null and b/2.sdk/project/W8/ext/static/AI/ai_result_can_start.png differ diff --git a/2.sdk/project/W8/ext/static/AI/ai_result_can_stop.png b/2.sdk/project/W8/ext/static/AI/ai_result_can_stop.png new file mode 100644 index 00000000..d58ea1fe Binary files /dev/null and b/2.sdk/project/W8/ext/static/AI/ai_result_can_stop.png differ diff --git a/2.sdk/project/W8/sdk/services/microPython/ports/quectel/core/ai.py b/2.sdk/project/W8/sdk/services/microPython/ports/quectel/core/ai.py index 6b3b82f5..71471c72 100644 --- a/2.sdk/project/W8/sdk/services/microPython/ports/quectel/core/ai.py +++ b/2.sdk/project/W8/sdk/services/microPython/ports/quectel/core/ai.py @@ -162,9 +162,9 @@ AI_talk_end_bt_screen.add_style(style_screen, lv.PART.MAIN | lv.STATE.DEFAULT) al_talk_end_screen_icon1 = lv.img(AI_talk_end_bt_screen) al_talk_end_screen_icon1.set_size(50,50) -al_talk_end_screen_icon1.set_pos(15,5) +al_talk_end_screen_icon1.set_pos(15,10) al_talk_end_screen_icon1.add_flag(lv.obj.FLAG.CLICKABLE) -al_talk_end_screen_icon1.set_src("E:/static/AI/ai_result_can_bt.png") +al_talk_end_screen_icon1.set_src("E:/static/AI/ai_result_can_start.png") al_talk_end_screen_icon1.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) al_talk_end_screen_cancel_bt = lv.label(AI_talk_end_bt_screen) @@ -175,7 +175,7 @@ al_talk_end_screen_cancel_bt.add_flag(lv.obj.FLAG.CLICKABLE) al_talk_end_screen_icon2 = lv.img(AI_talk_end_bt_screen) al_talk_end_screen_icon2.set_size(150,50) -al_talk_end_screen_icon2.set_pos(80,5) +al_talk_end_screen_icon2.set_pos(80,10) al_talk_end_screen_icon2.add_flag(lv.obj.FLAG.CLICKABLE) al_talk_end_screen_icon2.set_src("E:/static/AI/ai_result_bt.png") al_talk_end_screen_icon2.add_style(style_img, lv.PART.MAIN | lv.STATE.DEFAULT) @@ -189,7 +189,7 @@ AI_press_label_bt.add_flag(lv.obj.FLAG.CLICKABLE) AI_press_label = lv.label(al_talk_end_screen_icon2) AI_press_label.set_text("继续对话") AI_press_label.set_size(240-108, 50) -AI_press_label.set_pos(8,13) +AI_press_label.set_pos(8,18) AI_press_label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) AI_press_label.add_style(style_font_youyuan_20, lv.PART.MAIN | lv.STATE.DEFAULT) @@ -710,6 +710,9 @@ class AIScreen(Screen):#AI_GUI self.hard_flag_next = 0 self.hard_flag_prev = 0 self.scroll_timer_count = 0 + + self.play_flag = 0 + self.play_flag_init = 0 AI_screen.add_event_cb(lambda e: EventMesh.callback_wrapper(self.button_cb(e,1)), lv.EVENT.GESTURE, None) @@ -792,6 +795,18 @@ class AIScreen(Screen):#AI_GUI self.tts_time_outcount = 0 def talk_end_cancel_cb(self,e):#对话结束已经播放音频取消继续对话按钮 + if self.play_flag == 1: + self.play_flag = 0 + self.aud.stopPlayStream() + self.aud.stopAll() + print("talk_end_cancel_cb stop()\r\n") + EventMesh.publish("publish_message_event_ui",{"func":self.upload_img,"data":0}) + else: + self.play_flag = 1 + print("talk_end_cancel_cb start()\r\n") + EventMesh.publish("publish_message_event_ui",{"func":self.upload_img,"data":1}) + return + self.Close() self.AI_label_answer = "" AI_no_net_screen.add_flag(lv.obj.FLAG.HIDDEN) #隐藏 @@ -801,7 +816,11 @@ class AIScreen(Screen):#AI_GUI AI_talk_end_screen.add_flag(lv.obj.FLAG.HIDDEN) # AI_not_listen_text_screen.add_flag(lv.obj.FLAG.HIDDEN) # AI_talk_screen.clear_flag(lv.obj.FLAG.HIDDEN) # - + def upload_img(self,msg): + if msg == 1: + al_talk_end_screen_icon1.set_src("E:/static/AI/ai_result_can_start.png") + else: + al_talk_end_screen_icon1.set_src("E:/static/AI/ai_result_can_stop.png") def talk_end_continue_cb(self,e):#连接超时确定按钮回调或者继续对话按钮 self.Close() @@ -1044,7 +1063,7 @@ class AIScreen(Screen):#AI_GUI def ai_talk_end(self):#语言识别完 思考结束显示最后的文本和音频数据 - + self.play_flag = 1 self.AI_label_answer = "" AI_end_screen_list_screen.scroll_to(0, 0, lv.ANIM.OFF) @@ -1074,6 +1093,7 @@ class AIScreen(Screen):#AI_GUI AI_talk_screen.add_flag(lv.obj.FLAG.HIDDEN) # AI_not_listen_text_screen.add_flag(lv.obj.FLAG.HIDDEN) # AI_talk_end_screen.clear_flag(lv.obj.FLAG.HIDDEN) # + al_talk_end_screen_icon1.set_src("E:/static/AI/ai_result_can_start.png") AI_end_screen_list_screen2.add_flag(lv.obj.FLAG.HIDDEN) #隐藏2 AI_end_screen_list_screen.clear_flag(lv.obj.FLAG.HIDDEN) # @@ -1085,7 +1105,11 @@ class AIScreen(Screen):#AI_GUI pass def connect_timerout_popup(self,msg):#连接超时弹窗提示 + EventMesh.publish("publish_message_event_ui",{"func":self.connect_timerout_popup_cb,"data":msg}) + + def connect_timerout_popup_cb(self,msg): self.Close() + print("connect_timerout_popup!!!!!!\r\n") AI_talk_screen.add_flag(lv.obj.FLAG.HIDDEN) # AI_no_net_screen.add_flag(lv.obj.FLAG.HIDDEN) #隐藏 AI_listen_screen.add_flag(lv.obj.FLAG.HIDDEN) @@ -1167,6 +1191,7 @@ class AIScreen(Screen):#AI_GUI AI_talk_screen.clear_flag(lv.obj.FLAG.HIDDEN) # pass def initialization(self): + self.play_flag = 1 self.TTS_PRO_TYPE = 0 AI_listen_screen.add_flag(lv.obj.FLAG.HIDDEN) AI_think_screen.add_flag(lv.obj.FLAG.HIDDEN) #先隐藏 @@ -1439,6 +1464,7 @@ class AIScreen(Screen):#AI_GUI except Exception as e: #网络连接异常 usys.print_exception(e) print("websocket_connect_chat error!!!\r\n") + self.connect_timerout_popup(2) return # 线程接收数据 @@ -1544,7 +1570,8 @@ class AIScreen(Screen):#AI_GUI def AI_client_tts_timer_cb(self,*argc): # EventMesh.publish("system_sleep_rest")#防止黑屏 self.tts_time_count+=1 - + if self.play_flag == 0: + return if self.TTS_PRO_TYPE == 1: #tts数据入队 self.AI_client_tts_put_data() @@ -1658,7 +1685,7 @@ class AIScreen(Screen):#AI_GUI print("AI_client_tts_recv close!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\r\n") break try: - print("AI_client_tts_recv :{}".format(len(recv_data))) + # print("AI_client_tts_recv :{}".format(len(recv_data))) #结束标志{"header":{"event":"EndSynthesis","msg":"success","status":20000000,"task_id":"ffd727e620000803280c5a6498d0e321"}} if isinstance(recv_data, str): #print("AI_client_tts_recv:str recv_data:{}".format(recv_data)) @@ -1731,7 +1758,7 @@ class AIScreen(Screen):#AI_GUI try: _thread.stop_thread(self.AI_client_asr_recv_id) except Exception as e: - usys.print_exception(e) + usys.print_exception(e) self.AI_client_asr_recv_id = 0 self.AI_client_asr_recv_id = _thread.start_new_thread(self.AI_client_asr_recv, (self.AI_client_asr,)) self.AI_client_asr_isconnect = 1 @@ -1822,7 +1849,8 @@ class AIScreen(Screen):#AI_GUI self.websocket_connect_chat() except Exception as e: #网络连接异常 usys.print_exception(e) - tmp = self.AI_client_chat.send(data[1]) + if self.AI_client_chat != None: + tmp = self.AI_client_chat.send(data[1]) print("chat send_data:{} tmp:{}".format(len(data[1]),tmp)) if data[0] == self.AI_client_asr_num: if isinstance(data[1], str): @@ -1833,7 +1861,8 @@ class AIScreen(Screen):#AI_GUI except Exception as e: #网络连接异常 usys.print_exception(e) print("asr send_data:{}".format(len(data[1]))) - self.AI_client_asr.send(data[1]) + if self.AI_client_asr != None: + self.AI_client_asr.send(data[1]) if data[0] == self.AI_client_tts_num: if self.AI_client_tts_isconnect == 0: try: @@ -1841,7 +1870,8 @@ class AIScreen(Screen):#AI_GUI except Exception as e: #网络连接异常 usys.print_exception(e) print("tts send_data:{}".format((data[1]))) - self.AI_client_tts.send(data[1]) + if self.AI_client_tts != None: + self.AI_client_tts.send(data[1]) except Exception as e: print("DeviceInfo_queue_thread:ERROR:{}".format(e)) usys.print_exception(e) @@ -1871,7 +1901,8 @@ class AIScreen(Screen):#AI_GUI #self.AI_client_tts_start() if self.AI_client_tts_isconnect == 1: try: - self.AI_client_tts.send(data[1]) + if self.AI_client_tts != None: + self.AI_client_tts.send(data[1]) break except Exception as e: usys.print_exception(e) @@ -1884,28 +1915,35 @@ class AIScreen(Screen):#AI_GUI try: if 1: #self.audio_play_state == 0: #print("AI_audio_queue_thread") - data = self.AI_audio_queue.get() - - #self.AI_client_tts_data_len=len(data) - #print("audio_queue:len:{},data{}".format(len(data[0]),data[1])) - if len(data[0]) > 1: - if self.TTS_PRO_TYPE == 0: - - self.AI_label_answer+=data[1] - EventMesh.publish("publish_message_event_ui",{"func":self.ai_talk_end_show_text_cb,"data":0}) - # AI_label.set_text(self.AI_label_answer) - try: - - tmp= self.aud.playStream(3, data[0])#播放音频流 - print("出:{},{}!!!".format(len(data[0]),self.AI_client_tts_data_len)) - if tmp != 0: - print("2playStream:error tmp:{} data len:{}!!!!!!!!!!!!".format(tmp,len(data[0]))) - self.AI_client_tts_data_len -=len(data[0]) - mem = gc.mem_free() - print('1剩余内存RAM:{} KB'.format(mem / 1024)) - except Exception as e: - print("AI_audio_queue_thread:ERROR:") - usys.print_exception(e) + if self.play_flag == 1: + self.play_flag_init = 1 + data = self.AI_audio_queue.get() + + #self.AI_client_tts_data_len=len(data) + #print("audio_queue:len:{},data{}".format(len(data[0]),data[1])) + if len(data[0]) > 1: + if self.TTS_PRO_TYPE == 0: + if self.play_flag == 1: + self.AI_label_answer+=data[1] + EventMesh.publish("publish_message_event_ui",{"func":self.ai_talk_end_show_text_cb,"data":0}) + # AI_label.set_text(self.AI_label_answer) + try: + if self.play_flag == 1: + tmp= self.aud.playStream(3, data[0])#播放音频流 + print("出:{},{}!!!".format(len(data[0]),self.AI_client_tts_data_len)) + if tmp != 0: + print("2playStream:error tmp:{} data len:{}!!!!!!!!!!!!".format(tmp,len(data[0]))) + self.AI_client_tts_data_len -=len(data[0]) + mem = gc.mem_free() + print('1剩余内存RAM:{} KB'.format(mem / 1024)) + except Exception as e: + print("AI_audio_queue_thread:ERROR:") + usys.print_exception(e) + else: + if self.play_flag_init == 1: + self.play_flag_init = 0 + self.aud.stopPlayStream() + utime.sleep_ms(2) except Exception as e: print("AI_audio_queue_thread:ERROR:") usys.print_exception(e)