コード例 #1
0
    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
コード例 #2
0
    def in_speaking(self, message: Any, sender: RhasspyActor) -> None:
        """Handle messages in speaking state."""
        if isinstance(message, WavPlayed):
            self.transition("ready")
            self.send(self.receiver, SentenceSpoken(self.wav_data))

            if self.wake and self.enable_wake:
                # Re-enable wake word
                self.send(self.wake, ResumeListeningForWakeWord())
コード例 #3
0
    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))
コード例 #4
0
 def in_started(self, message: Any, sender: RhasspyActor) -> None:
     """Handle messages in started state."""
     if isinstance(message, SpeakSentence):
         self.send(message.receiver or sender, SentenceSpoken())