@@ -74,7 +74,9 @@ def stop_dictation(self, message=None):
7474 name = self .dictation_sessions [sess .session_id ]["file_name" ] or time .time ()
7575 with open (f"{ path } /{ name } .txt" , "w" ) as f :
7676 f .write ("\n " .join (self .dictation_sessions [sess .session_id ]["dictation_stack" ]))
77- self .gui .show_text (f"saved to { path } /{ name } .txt" )
77+
78+ if sess .session_id == "default" :
79+ self .gui .show_text (f"saved to { path } /{ name } .txt" )
7880
7981 self .dictation_sessions [sess .session_id ]["dictating" ] = False
8082
@@ -94,6 +96,10 @@ def handle_stop_dictation_intent(self, message):
9496 self .speak_dialog ("not_dictating" )
9597 self .stop_dictation (message )
9698
99+ def can_stop (self , message : Message ) -> bool :
100+ session = SessionManager .get (message )
101+ return session .session_id in self .dictation_sessions and self .dictation_sessions [session .session_id ]["dictating" ]
102+
97103 def stop_session (self , session : Session ):
98104 if session .session_id in self .dictation_sessions and \
99105 self .dictation_sessions [session .session_id ]["dictating" ]:
@@ -102,14 +108,6 @@ def stop_session(self, session: Session):
102108 return True
103109 return False
104110
105- def stop (self ):
106- sess = SessionManager .get ()
107- if sess .session_id in self .dictation_sessions and \
108- self .dictation_sessions [sess .session_id ]["dictating" ]:
109- self .stop_session (sess )
110- return True
111- return False
112-
113111 def can_answer (self , message : Message ) -> bool :
114112 """
115113 Determines if the skill can handle the given utterances in the specified language in the converse method.
@@ -119,47 +117,14 @@ def can_answer(self, message: Message) -> bool:
119117 Returns:
120118 True if the skill can handle the query during converse; otherwise, False.
121119 """
122- sess = SessionManager .get (message )
123- if sess .session_id in self .dictation_sessions and \
124- self .dictation_sessions [sess .session_id ]["dictating" ]:
125- return True
126- return False
120+ return self .can_stop (message ) # same logic
127121
128122 def converse (self , message ):
129123 utterance = message .data ["utterances" ][0 ]
130124 sess = SessionManager .get (message )
131- if sess .session_id in self .dictation_sessions and \
132- self .dictation_sessions [sess .session_id ]["dictating" ]:
133- if self .voc_match (utterance , "StopKeyword" ):
134- self .handle_stop_dictation_intent (message )
135- else :
125+ if self .voc_match (utterance , "StopKeyword" ):
126+ self .handle_stop_dictation_intent (message )
127+ else :
128+ if sess .session_id == "default" :
136129 self .gui .show_text (utterance )
137- self .dictation_sessions [sess .session_id ]["dictation_stack" ].append (utterance )
138- return True
139- return False
140-
141-
142- if __name__ == "__main__" :
143- from ovos_utils .fakebus import FakeBus
144-
145-
146- # print speak for debugging
147- def spk (utt , * args , ** kwargs ):
148- print (utt )
149-
150-
151- s = DictationSkill (skill_id = "fake.test" , bus = FakeBus ())
152- s .speak = spk
153-
154- s .handle_stop_dictation_intent (Message ("" ))
155- # I am not dictating at this moment
156- s .handle_start_dictation_intent (Message ("" ))
157- # ok, i am ready for dictation
158- s .converse (Message ("" , {"utterances" : ["test" ]}))
159- s .converse (Message ("" , {"utterances" : ["test" ]}))
160- s .converse (Message ("" , {"utterances" : ["test" ]}))
161- s .converse (Message ("" , {"utterances" : ["stop" ]}))
162- # dictation stopped
163- s .converse (Message ("" , {"utterances" : ["test" ]}))
164-
165- assert s .dictation_stack == ['test' , 'test' , 'test' ]
130+ self .dictation_sessions [sess .session_id ]["dictation_stack" ].append (utterance )
0 commit comments