77from langcodes import closest_match
88from ovos_bus_client .client import MessageBusClient
99from ovos_bus_client .message import Message
10- from ovos_bus_client .session import SessionManager
10+ from ovos_bus_client .session import SessionManager , UtteranceState
1111
1212from ovos_config .config import Configuration
1313from ovos_plugin_manager .templates .pipeline import ConfidenceMatcherPipeline , IntentHandlerMatch
@@ -29,12 +29,17 @@ def __init__(self, bus: Optional[Union[MessageBusClient, FakeBus]] = None,
2929 self ._voc_cache = {}
3030 self .load_resource_files ()
3131 self .bus .on ("stop:global" , self .handle_global_stop )
32+ self .bus .on ("stop:skill" , self .handle_skill_stop )
3233
3334 def handle_global_stop (self , message : Message ):
3435 self .bus .emit (message .forward ("mycroft.stop" ))
3536 # TODO - this needs a confirmation dialog if nothing was stopped
3637 self .bus .emit (message .forward ("ovos.utterance.handled" ))
3738
39+ def handle_skill_stop (self , message : Message ):
40+ skill_id = message .data ["skill_id" ]
41+ self .bus .emit (message .reply (f"{ skill_id } .stop" ))
42+
3843 def load_resource_files (self ):
3944 base = f"{ dirname (__file__ )} /locale"
4045 for lang in os .listdir (base ):
@@ -148,11 +153,21 @@ def handle_stop_confirmation(self, message: Message):
148153 error_msg = message .data ['error' ]
149154 LOG .error (f"{ skill_id } : { error_msg } " )
150155 elif message .data .get ('result' , False ):
151- # force-kill any ongoing get_response/converse/TTS - see @killable_event decorator
152- self .bus .emit (message .forward ("mycroft.skills.abort_question" , {"skill_id" : skill_id }))
153- self .bus .emit (message .forward ("ovos.skills.converse.force_timeout" , {"skill_id" : skill_id }))
154- # TODO - track if speech is coming from this skill! not currently tracked
155- self .bus .emit (message .reply ("mycroft.audio.speech.stop" , {"skill_id" : skill_id }))
156+ sess = SessionManager .get (message )
157+ utt_state = sess .utterance_states .get (skill_id , UtteranceState .INTENT )
158+ if utt_state == UtteranceState .RESPONSE :
159+ LOG .debug ("Forcing get_response timeout" )
160+ # force-kill any ongoing get_response - see @killable_event decorator (ovos-workshop)
161+ self .bus .emit (message .reply ("mycroft.skills.abort_question" , {"skill_id" : skill_id }))
162+ if sess .is_active (skill_id ):
163+ LOG .debug ("Forcing converse timeout" )
164+ # force-kill any ongoing converse - see @killable_event decorator (ovos-workshop)
165+ self .bus .emit (message .reply ("ovos.skills.converse.force_timeout" , {"skill_id" : skill_id }))
166+
167+ # TODO - track if speech is coming from this skill! not currently tracked (ovos-audio)
168+ if sess .is_speaking :
169+ # force-kill any ongoing TTS
170+ self .bus .emit (message .forward ("mycroft.audio.speech.stop" , {"skill_id" : skill_id }))
156171
157172 def match_high (self , utterances : List [str ], lang : str , message : Message ) -> Optional [IntentHandlerMatch ]:
158173 """
@@ -211,8 +226,8 @@ def match_high(self, utterances: List[str], lang: str, message: Message) -> Opti
211226 sess .disable_response_mode (skill_id )
212227 self .bus .once (f"{ skill_id } .stop.response" , self .handle_stop_confirmation )
213228 return IntentHandlerMatch (
214- match_type = f" { skill_id } . stop" ,
215- match_data = {"conf" : conf },
229+ match_type = " stop:skill " ,
230+ match_data = {"conf" : conf , "skill_id" : skill_id },
216231 updated_session = sess ,
217232 utterance = utterance ,
218233 skill_id = "stop.openvoiceos"
@@ -299,8 +314,8 @@ def match_low(self, utterances: List[str], lang: str, message: Message) -> Optio
299314 sess .disable_response_mode (skill_id )
300315 self .bus .once (f"{ skill_id } .stop.response" , self .handle_stop_confirmation )
301316 return IntentHandlerMatch (
302- match_type = f" { skill_id } . stop" ,
303- match_data = {"conf" : conf },
317+ match_type = " stop:skill " ,
318+ match_data = {"conf" : conf , "skill_id" : skill_id },
304319 updated_session = sess ,
305320 utterance = utterance ,
306321 skill_id = "stop.openvoiceos"
0 commit comments