def in_ready(self, message: Any, sender: RhasspyActor) -> None: """Handle messages in rady state.""" if isinstance(message, SpeakSentence): self.wav_data = bytes() self.receiver = message.receiver or sender try: voice = message.voice or self.voice language_code = message.language or self.language_code self.wav_data = self.speak(message.sentence, voice, language_code) if message.play: self.enable_wake = False if self.wake and self.disable_wake: # Disable wake word self.send(self.wake, PauseListeningForWakeWord()) self.enable_wake = self.wake_on_start self.transition("speaking") self.send( self.player, PlayWavData(self.wav_data, siteId=message.siteId)) else: self.transition("ready") self.send(self.receiver, SentenceSpoken(self.wav_data)) except Exception: self._logger.exception("speak") # Try fallback system try: assert (self.fallback_actor is not None), "No fallback text to speech system" self._logger.debug("Falling back to %s", self.fallback_actor) self.transition("speaking") self.send( self.fallback_actor, SpeakSentence( message.sentence, play=message.play, voice=message.voice, language=message.language, siteId=message.siteId, ), ) except Exception: # Give up self.transition("ready") self.send(self.receiver, SentenceSpoken(bytes())) elif isinstance(message, Configured): # Fallback actor is configured pass
def in_ready(self, message: Any, sender: RhasspyActor) -> None: """Handle messages in ready state.""" if isinstance(message, SpeakSentence): self.receiver = message.receiver or sender self.wav_data = self.speak(message.sentence) if message.play: self.enable_wake = False if self.wake and self.disable_wake: # Disable wake word self.send(self.wake, PauseListeningForWakeWord()) self.enable_wake = self.wake_on_start self.transition("speaking") self.send(self.player, PlayWavData(self.wav_data)) else: self.transition("ready") self.send(self.receiver, SentenceSpoken(self.wav_data))
def play_wav_data(self, wav_data: bytes) -> None: """Play WAV buffer through audio playback system.""" assert self.actor_system is not None self.actor_system.tell(self.dialogue_manager, PlayWavData(wav_data))