File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ def __init__(self):
6262 self .backends = {}
6363 self .llm_models = set ()
6464 self .asr_models = set ()
65+ self .tts_models = set ()
6566 self .lock = asyncio .Lock ()
6667
6768 async def get_backend (self , model_name ):
@@ -84,7 +85,14 @@ async def get_backend(self, model_name):
8485 elif model_config ["type" ] == "vision_model" :
8586 self .backends [model_name ] = VisionModelBackend (model_config )
8687 elif model_config ["type" ] == "tts" :
88+ if model_name not in self .tts_models :
89+ for old_model_name in list (self .tts_models ):
90+ old_instance = self .backends .pop (old_model_name , None )
91+ if old_instance :
92+ await old_instance .close ()
93+ self .asr_models .clear ()
8794 self .backends [model_name ] = TtsClientBackend (model_config )
95+ self .tts_models .add (model_name )
8896 elif model_config ["type" ] == "asr" :
8997 if model_name not in self .asr_models :
9098 for old_model_name in list (self .asr_models ):
Original file line number Diff line number Diff line change @@ -82,6 +82,17 @@ async def _release_client(self, client):
8282 async with self ._pool_lock :
8383 self ._client_pool .append (client )
8484
85+ async def close (self ):
86+ for task in self ._active_tasks :
87+ task .cancel ()
88+ if self ._active_tasks :
89+ await asyncio .wait (self ._active_tasks , timeout = 2 )
90+ for client in self ._client_pool :
91+ client .exit ()
92+ self ._client_pool .clear ()
93+ self ._active_clients .clear ()
94+ self ._inference_executor .shutdown (wait = False )
95+
8596 def _encode_stream_chunk (self , pcm_data : bytes , format : str ) -> bytes :
8697 if format == "pcm" :
8798 return pcm_data
You can’t perform that action at this time.
0 commit comments