async def transcribe_wav(self, wav_data: bytes) -> WavTranscription: """Transcribe text from WAV buffer.""" assert self.actor_system is not None with self.actor_system.private() as sys: result = await sys.async_ask(self.dialogue_manager, TranscribeWav(wav_data, handle=False)) assert isinstance(result, WavTranscription), result return result
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 handle_any(self, message: Any, sender: RhasspyActor) -> None: """Handle messages in any state.""" if isinstance(message, ListenForCommand): # Force voice command self.handle = message.handle self.intent_receiver = message.receiver or sender self.listen_timeout_sec = message.timeout self.listen_entities = message.entities self.transition("awake") elif isinstance(message, GetVoiceCommand): # Record voice command, but don't do anything with it self.send( self.command, ListenForCommand(message.receiver or sender, timeout=message.timeout), ) elif isinstance(message, TranscribeWav): # speech -> text self.send( self.decoder, TranscribeWav(message.wav_data, sender, handle=message.handle), ) elif isinstance(message, RecognizeIntent): # text -> intent self.send( self.recognizer, RecognizeIntent( message.text, confidence=message.confidence, receiver=sender, handle=message.handle, ), ) elif isinstance(message, HandleIntent): # intent -> action self.send(self.handler, HandleIntent(message.intent, sender)) # Forward to MQTT (hermes) if self.mqtt is not None: self.send(self.mqtt, IntentRecognized(message.intent)) elif isinstance(message, GetWordPhonemes): # eSpeak -> CMU self.send( self.word_pronouncer, GetWordPhonemes(message.word, receiver=sender) ) elif isinstance(message, SpeakWord): # eSpeak -> WAV self.send(self.word_pronouncer, SpeakWord(message.word, receiver=sender)) elif isinstance(message, GetWordPronunciations): # word -> [CMU] self.send( self.word_pronouncer, GetWordPronunciations(message.words, n=message.n, receiver=sender), ) elif isinstance(message, SpeakSentence): # text -> speech self.send( self.speech, SpeakSentence( message.sentence, receiver=sender, play=message.play, voice=message.voice, language=message.language, ), ) elif isinstance(message, TrainProfile): # Training self.reload_actors_after_training = message.reload_actors self.send(self.wake, StopListeningForWakeWord()) self.training_receiver = message.receiver or sender self.transition("training_sentences") # self.send(self.sentence_generator, GenerateSentences()) elif isinstance(message, StartRecordingToBuffer): # Record WAV self.send(self.recorder, message) elif isinstance(message, StopRecordingToBuffer): # Stop recording WAV self.send( self.recorder, StopRecordingToBuffer(message.buffer_name, message.receiver or sender), ) elif isinstance(message, StateTransition): # Track state of every actor self.handle_transition(message, sender) elif isinstance(message, GetActorStates): self.send(sender, self.actor_states) elif isinstance(message, WakeupMessage): pass elif isinstance(message, WavPlayed): pass elif isinstance(message, GetProblems): # Report problems from child actors self.send(sender, Problems(self.problems)) else: self.handle_forward(message, sender)