def _process_event(self, event): from google.assistant.library.event import EventType, AlertType self.logger.info('Received assistant event: {}'.format(event)) self._has_error = False if event.type == EventType.ON_CONVERSATION_TURN_STARTED: self.bus.post(ConversationStartEvent(assistant=self)) elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED: if not event.args.get('with_follow_on_turn'): self.bus.post(ConversationEndEvent(assistant=self)) elif event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT: self.bus.post(ConversationTimeoutEvent(assistant=self)) elif event.type == EventType.ON_NO_RESPONSE: self.bus.post(NoResponseEvent(assistant=self)) elif hasattr(EventType, 'ON_RENDER_RESPONSE') and \ event.type == EventType.ON_RENDER_RESPONSE: self.bus.post( ResponseEvent(assistant=self, response_text=event.args.get('text'))) tts, args = self._get_tts_plugin() if tts and 'text' in event.args: self.stop_conversation() tts.say(text=event.args['text'], **args) elif hasattr(EventType, 'ON_RESPONDING_STARTED') and \ event.type == EventType.ON_RESPONDING_STARTED and \ event.args.get('is_error_response', False) is True: self.logger.warning('Assistant response error') elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED: phrase = event.args['text'].lower().strip() self.logger.info('Speech recognized: {}'.format(phrase)) self.bus.post(SpeechRecognizedEvent(assistant=self, phrase=phrase)) elif event.type == EventType.ON_ALERT_STARTED: if event.args.get('alert_type') == AlertType.ALARM: self.bus.post(AlarmStartedEvent(assistant=self)) elif event.args.get('alert_type') == AlertType.TIMER: self.bus.post(TimerStartedEvent(assistant=self)) else: self.bus.post(AlertStartedEvent(assistant=self)) elif event.type == EventType.ON_ALERT_FINISHED: if event.args.get('alert_type') == AlertType.ALARM: self.bus.post(AlarmEndEvent(assistant=self)) elif event.args.get('alert_type') == AlertType.TIMER: self.bus.post(TimerEndEvent(assistant=self)) else: self.bus.post(AlertEndEvent(assistant=self)) elif event.type == EventType.ON_ASSISTANT_ERROR: self._has_error = True if event.args.get('is_fatal'): self.logger.error('Fatal assistant error') else: self.logger.warning('Assistant error') if event.type == EventType.ON_MUTED_CHANGED: self._is_muted = event.args.get('is_muted') event = MicMutedEvent() if self._is_muted else MicUnmutedEvent() self.bus.post(event)
def _process_event(self, event): logging.info('Received assistant event: {}'.format(event)) if event.type == EventType.ON_CONVERSATION_TURN_STARTED: self.bus.post(ConversationStartEvent()) elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED: self.bus.post(ConversationEndEvent()) elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED: phrase = event.args['text'].lower().strip() logging.info('Speech recognized: {}'.format(phrase)) self.bus.post(SpeechRecognizedEvent(phrase=phrase))
def _process_event(self, event): self.logger.info('Received assistant event: {}'.format(event)) self._has_error = False if event.type == EventType.ON_CONVERSATION_TURN_STARTED: self.bus.post(ConversationStartEvent()) elif event.type == EventType.ON_CONVERSATION_TURN_FINISHED: if not event.args.get('with_follow_on_turn'): self.bus.post(ConversationEndEvent()) elif event.type == EventType.ON_CONVERSATION_TURN_TIMEOUT: self.bus.post(ConversationTimeoutEvent()) elif event.type == EventType.ON_NO_RESPONSE: self.bus.post(NoResponseEvent()) elif hasattr(EventType, 'ON_RENDER_RESPONSE') and \ event.type == EventType.ON_RENDER_RESPONSE: self.bus.post(ResponseEvent(response_text=event.args.get('text'))) elif hasattr(EventType, 'ON_RESPONDING_STARTED') and \ event.type == EventType.ON_RESPONDING_STARTED and \ event.args.get('is_error_response', False) is True: self.logger.warning('Assistant response error') elif event.type == EventType.ON_RECOGNIZING_SPEECH_FINISHED: phrase = event.args['text'].lower().strip() self.logger.info('Speech recognized: {}'.format(phrase)) self.bus.post(SpeechRecognizedEvent(phrase=phrase)) elif event.type == EventType.ON_ALERT_STARTED: if event.args.get('alert_type') == AlertType.ALARM: self.bus.post(AlarmStartedEvent()) elif event.args.get('alert_type') == AlertType.TIMER: self.bus.post(TimerStartedEvent()) else: self.bus.post(AlertStartedEvent()) elif event.type == EventType.ON_ALERT_FINISHED: if event.args.get('alert_type') == AlertType.ALARM: self.bus.post(AlarmEndEvent()) elif event.args.get('alert_type') == AlertType.TIMER: self.bus.post(TimerEndEvent()) else: self.bus.post(AlertEndEvent()) elif event.type == EventType.ON_ASSISTANT_ERROR: self._has_error = True if event.args.get('is_fatal'): self.logger.error('Fatal assistant error') else: self.logger.warning('Assistant error')
def handler(): get_bus().post(ConversationStartEvent(assistant=self))
def _callback(): get_bus().post(ConversationStartEvent(assistant=self))
def handler(): get_bus().post(ConversationStartEvent())
def on_conversation_start(self): self.bus.post(ConversationStartEvent())