def in_recognizing(self, message: Any, sender: RhasspyActor) -> None: """Handle messages in recognizing state.""" if isinstance(message, IntentRecognized): if not pydash.get(message.intent, "intent.name", ""): if self.profile.get("intent.error_sound", True): # Play error sound when not recognized wav_path = os.path.expandvars( self.profile.get("sounds.error", None) ) if wav_path is not None: self.send(self.player, PlayWavFile(wav_path)) if self.recorder_class == HTTPAudioRecorder: # Forward to audio recorder self.send(self.recorder, message) message.intent["wakeId"] = self.wake_detected_name or "" message.intent["siteId"] = self.site_id # Augment with extra entities entities = message.intent.get("entities", []) entities.extend(self.listen_entities) message.intent["entities"] = entities slots = message.intent.get("slots", {}) for entity_dict in self.listen_entities: slots[entity_dict["entity"]] = entity_dict["value"] # Handle intent self._logger.debug(message.intent) if message.handle: # Forward to Home Assistant self.send(self.handler, HandleIntent(message.intent)) # Forward to MQTT (hermes) if self.mqtt is not None: self.send(self.mqtt, message) # Forward to observer if self.observer: self.send(self.observer, message) self.transition("handling") else: self._logger.debug("Not actually handling intent") if self.intent_receiver is not None: self.send(self.intent_receiver, message.intent) self.transition("ready") else: self.handle_any(message, sender)
def in_awake(self, message: Any, sender: RhasspyActor) -> None: """Handle messages in awake state.""" if isinstance(message, VoiceCommand): # Recorded beep wav_path = os.path.expandvars(self.profile.get("sounds.recorded", None)) if wav_path is not None: self.send(self.player, PlayWavFile(wav_path)) # speech -> text wav_data = buffer_to_wav(message.data) self.send(self.decoder, TranscribeWav(wav_data, handle=message.handle)) self.transition("decoding") else: self.handle_any(message, sender)
def to_awake(self, from_state: str) -> None: """Transition to awake state.""" self.send(self.wake, StopListeningForWakeWord()) # Wake up beep wav_path = os.path.expandvars(self.profile.get("sounds.wake", None)) if wav_path is not None: self.send(self.player, PlayWavFile(wav_path)) # Listen for a voice command self.send( self.command, ListenForCommand( self.myAddress, handle=self.handle, timeout=self.listen_timeout_sec ), )
def play_wav_file(self, wav_path: str) -> None: """Play WAV file through audio playback system.""" assert self.actor_system is not None self.actor_system.tell(self.dialogue_manager, PlayWavFile(wav_path))