@@ -143,14 +143,17 @@ public static IReadOnlyList<string> SystemLanguages()
143143 return [ CultureInfo . CurrentUICulture . Name ] ;
144144 }
145145
146+ public AsrModel ActiveAsrModel => AsrModels . Parse ( Settings . AsrModel ) ;
147+ public bool ModelsReady => Models . IsReady ( ActiveAsrModel ) ;
148+
146149 /// Ensures the speech recognizer and meeting controller are loaded; returns false when models are missing or fail to load.
147150 public async Task < bool > EnsureEnginesAsync ( )
148151 {
149152 Task < bool > task ;
150153 lock ( engineGate )
151154 {
152155 if ( Meeting != null ) return true ;
153- if ( ! Models . Ready ) return false ;
156+ if ( ! ModelsReady ) return false ;
154157 if ( loading == null )
155158 {
156159 isLoading = true ;
@@ -190,11 +193,16 @@ private bool LoadCore()
190193 {
191194 var watch = System . Diagnostics . Stopwatch . StartNew ( ) ;
192195 var threads = Math . Clamp ( System . Environment . ProcessorCount / 2 , 2 , 4 ) ;
193- rec = new Recognizer ( Models , threads : threads )
196+ var asrModel = ActiveAsrModel ;
197+ var asrLang = Settings . AsrLanguage ;
198+ rec = new Recognizer ( Models , threads : threads , model : asrModel , language : asrLang )
194199 {
195200 Fix = text => Settings . GlossaryOn ? Glossary . FixWithDetails ( text ) : ( text , [ ] )
196201 } ;
197- listen = new ListenEngine ( rec , Models , TimeSpan . FromMilliseconds ( 600 ) ) ;
202+ // Whisper decodes autoregressively over a 30 s window: disable live partials on mobile so
203+ // slow decoders never spiral into latency backlog; SenseVoice keeps 600 ms live drafts.
204+ var partialInterval = AsrModels . IsWhisper ( asrModel ) ? TimeSpan . Zero : TimeSpan . FromMilliseconds ( 600 ) ;
205+ listen = new ListenEngine ( rec , Models , partialInterval ) ;
198206 // Voiceprints load lazily on first use; without the model, lines stay unlabelled.
199207 Voiceprints ? Prints ( )
200208 {
@@ -256,7 +264,7 @@ private bool LoadCore()
256264 listenEngine = listen ;
257265 Meeting = meeting ;
258266 }
259- Log . Debug ( $ "app: recognizer loaded in { watch . ElapsedMilliseconds } ms (threads={ threads } )") ;
267+ Log . Debug ( $ "app: recognizer ( { AsrModels . IdOf ( asrModel ) } , lang= { asrLang } ) loaded in { watch . ElapsedMilliseconds } ms (threads={ threads } )") ;
260268 return true ;
261269 }
262270 catch
@@ -271,6 +279,61 @@ private bool LoadCore()
271279 }
272280 }
273281
282+ /// Switches the active ASR model (and/or Whisper language hint) when idle, unloading old engines.
283+ public async Task < bool > SwitchAsrModelAsync ( AsrModel nextModel , string ? language = null )
284+ {
285+ if ( IsListening ) return false ;
286+ Settings . AsrModel = AsrModels . IdOf ( nextModel ) ;
287+ if ( language != null ) Settings . AsrLanguage = language ;
288+ Settings . Save ( ) ;
289+ Task < bool > ? pending ;
290+ lock ( engineGate ) pending = loading ;
291+ if ( pending != null )
292+ {
293+ try { await pending ; } catch { }
294+ }
295+ DisposeCachedEngines ( ) ;
296+ Ui ( ( ) => StateChanged ? . Invoke ( ) ) ;
297+ if ( Models . IsReady ( nextModel ) )
298+ {
299+ var ok = await EnsureEnginesAsync ( ) ;
300+ Ui ( ( ) => StateChanged ? . Invoke ( ) ) ;
301+ return ok ;
302+ }
303+ return true ;
304+ }
305+
306+ private void DisposeCachedEngines ( )
307+ {
308+ Recognizer ? rec ;
309+ Voiceprints ? prints ;
310+ ListenEngine ? listen ;
311+ lock ( engineGate )
312+ {
313+ rec = Recognizer ;
314+ prints = voiceprints ;
315+ listen = listenEngine ;
316+ Recognizer = null ;
317+ voiceprints = null ;
318+ printsFailed = false ;
319+ listenEngine = null ;
320+ Meeting = null ;
321+ loading = null ;
322+ }
323+ try { listen ? . Dispose ( ) ; } catch { }
324+ try { prints ? . Dispose ( ) ; } catch { }
325+ try { rec ? . Dispose ( ) ; } catch { }
326+ }
327+
328+ /// Deletes a non-active ASR model's files to free device storage.
329+ public bool DeleteAsrModel ( AsrModel target )
330+ {
331+ if ( IsListening || target == ActiveAsrModel ) return false ;
332+ Models . DeleteAsr ( target ) ;
333+ Ui ( ( ) => StateChanged ? . Invoke ( ) ) ;
334+ return true ;
335+ }
336+
274337 public Task StartMeeting ( Context context )
275338 {
276339 ArgumentNullException . ThrowIfNull ( context ) ;
0 commit comments