def in_decoding(self, message: Any, sender: RhasspyActor) -> None: """Handle messages in decoding state.""" if isinstance(message, WavTranscription): message.wakewordId = self.wake_detected_name or "default" # Fix casing dict_casing = self.profile.get("speech_to_text.dictionary_casing", "") if dict_casing == "lower": message.text = message.text.lower() elif dict_casing == "upper": message.text = message.text.upper() # text -> intent self._logger.debug("%s (confidence=%s)", message.text, message.confidence) if self.recorder_class == HTTPAudioRecorder: # Forward to audio recorder self.send(self.recorder, message) # Send to MQTT payload = json.dumps( { "siteId": self.site_id, "text": message.text, "likelihood": 1, "seconds": 0, "wakeId": message.wakewordId, "wakewordId": message.wakewordId, } ).encode() if self.mqtt is not None: self.send( self.mqtt, MqttPublish( "rhasspy/speech-to-text/transcription", message.text.encode() ), ) self.send(self.mqtt, MqttPublish("hermes/asr/textCaptured", payload)) # Forward to observer if self.observer: self.send(self.observer, message) # Pass to intent recognizer self.send( self.recognizer, RecognizeIntent( message.text, confidence=message.confidence, handle=message.handle ), ) self.transition("recognizing") else: self.handle_any(message, sender)
def handle_transition(self, message: StateTransition, sender: RhasspyActor) -> None: """Report state transition of actor.""" self.actor_states[message.name] = message.to_state topic = "rhasspy/%s/transition/%s" % (self.profile.name, message.name) payload = message.to_state.encode() if self.mqtt is not None: self.send(self.mqtt, MqttPublish(topic, payload))
def play_data(self, wav_data: bytes) -> None: """Send WAV buffer over MQTT.""" request_id = str(uuid.uuid4()) # Send to all site ids for site_id in self.site_ids: topic = f"hermes/audioServer/{site_id}/playBytes/{request_id}" self.send(self.mqtt, MqttPublish(topic, wav_data))
def play_data(self, wav_data: bytes, siteId: Optional[str] = None) -> None: """Send WAV buffer over MQTT.""" request_id = str(uuid.uuid4()) if siteId: # Send to a specific site id publish_sites = [siteId] else: # Send to all site ids publish_sites = self.site_ids # Send to all site ids for site_id in publish_sites: topic = f"hermes/audioServer/{site_id}/playBytes/{request_id}" self.send(self.mqtt, MqttPublish(topic, wav_data))
def mqtt_publish(self, topic: str, payload: bytes) -> None: """Publish a payload to an MQTT topic.""" assert self.actor_system is not None with self.actor_system.private() as sys: sys.tell(self.dialogue_manager, MqttPublish(topic, payload))