33from queue import Queue , Empty
44import re
55
6- from maix ._maix .image import Image
7-
86class PagedText :
97 def __init__ (self , page_width = - 1 , page_height = - 1 ):
108 """
@@ -126,16 +124,21 @@ def __init__(self):
126124 ai_isp_on = bool (int (app .get_sys_config_kv ("npu" , "ai_isp" , "1" )))
127125 if ai_isp_on is True :
128126 img = image .Image (320 , 240 , bg = image .COLOR_BLACK )
129- err_msg = "You need edit /boot/configs to set ai_isp_on to 0"
130- err_msg_size = image .string_size (err_msg )
131- img .draw_string ((img .width () - err_msg_size .width ()) // 2 , (img .height () - err_msg_size .height ()) // 2 , err_msg , image .COLOR_RED )
127+ err_title_msg = "Ops!!!"
128+ err_msg = "You need open the Settings app, find the AI ISP option, and select Off."
129+ err_exit_msg = "Tap anywhere on the screen to exit."
130+ img .draw_string (0 , 0 , err_title_msg , image .COLOR_WHITE , 0.8 )
131+ img .draw_string (0 , 20 , err_msg , image .COLOR_WHITE , 0.8 )
132+ img .draw_string (0 , 200 , err_exit_msg , image .COLOR_WHITE , 0.6 )
132133 self .disp .show (img )
133134 while not app .need_exit ():
134135 ts_data = self .ts .read ()
135136 if ts_data [2 ]:
136137 app .set_exit_flag (True )
137138 time .sleep_ms (100 )
139+ exit (0 )
138140 self .whisper = nn .Whisper (model = "/root/models/whisper-base/whisper-base.mud" , language = "en" )
141+ self .whisper_thread = None
139142
140143 self .__show_load_info ('loading llm..' )
141144 # /root/models/Qwen2.5-0.5B-Instruct/model.mud
@@ -189,6 +192,17 @@ def tts_thread_handle(self):
189192 except Empty :
190193 continue
191194
195+ def _whisper_thread_handle (self , path ):
196+ self .whisper_results = self .whisper .transcribe (path )
197+
198+ def run_whisper (self , path :str ):
199+ if self .whisper_thread :
200+ if self .whisper_thread .is_alive ():
201+ self .whisper_thread .join ()
202+ self .whisper_thread = None
203+ self .whisper_thread = threading .Thread (target = self ._whisper_thread_handle , args = [path ])
204+ self .whisper_thread .start ()
205+
192206 def __llm_on_reply (self , obj , resp ):
193207 print (resp .msg_new , end = "" )
194208 ts_data = self .ts .read ()
@@ -207,6 +221,7 @@ def __llm_on_reply(self, obj, resp):
207221 if ts_data [2 ] and 0 <= ts_data [0 ]<= self .exit_img .width () + exit_img_x * 2 and 0 <= ts_data [1 ]<= self .exit_img .height () + exit_img_y * 2 :
208222 print ('exit' )
209223 app .set_exit_flag (True )
224+ exit (0 )
210225 self .disp .show (img )
211226
212227 self .llm_last_msg += resp .msg_new
@@ -312,7 +327,7 @@ class Status:
312327 app .set_exit_flag (True )
313328 self .disp .show (img )
314329
315- if status == Status .IDLE :
330+ if status == Status .IDLE :
316331 if ts_data [2 ]:
317332 if self .vad :
318333 start_vad = not start_vad
@@ -337,9 +352,16 @@ class Status:
337352 self .__reset_recorder (False )
338353 status = Status .TRANSCRIBE
339354 elif status == Status .TRANSCRIBE :
340- asr_result = self .whisper .transcribe (self .default_wav_path )
341- print (asr_result )
342- status = Status .LLM
355+ if not self .whisper_thread :
356+ # 未创建线程, 开运行whisper
357+ self .run_whisper (self .default_wav_path )
358+ else :
359+ # 线程结束, whisper出了结果
360+ if not self .whisper_thread .is_alive ():
361+ self .whisper_thread = None
362+ asr_result = self .whisper_results
363+ print (asr_result )
364+ status = Status .LLM
343365 elif status == Status .LLM :
344366 if asr_result :
345367 self .page_text .reset (320 , 210 )
0 commit comments