Add tts-finished state to simple_state sensor, continue_conversation switch and custom_responses_blueprint#22
Open
Add tts-finished state to simple_state sensor, continue_conversation switch and custom_responses_blueprint#22
Conversation
…switch and custom_responses_blueprint
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello. Congratulations on what you've been able to do with this integration. In order to be able to properly implement Hassmic integration in the ViewAssist project, I made some changes to the code.
One of the things needed to use this integration is to be as precise as possible when the tts message actually finishes playing because TTS_END marks when the message is sent to the player and not when it finishes playing. That's why I took this implementation from the StreamAssist integration and looked for the best way to implement it in Hassmic. Practically, when the TTS_END event is executed, the URL of the tts is taken and using mutagen.mp3 to calculate the effective duration of the message. Then in the SimpeState sensor I put a new state tts-finished.
There is a problem though with the fact that the wake_word-listening state fires before the message finishes playing and at the end it remains as the last state
tts-finishedand notwake_word-listening. That's why I modified the code to respect the order of publishing the statuses:stt-speaking,stt-listeningand at the endwake_word-listeningorstt-listening, depending on how the continue conversation switch is set. Practically, I added a delay in the publication of wake_word-listening or stt-listening statuses until the tts message is finished playing. This does not affect the functionality of the satellite in any way because theSimple state sensoris just a sensor made especially for the View Assist project. Listening to the wake word starts immediately after TTS-END, but in order for the avatar to remain talking until the end of the message playback, this is necessary.I also added a switch to enable continue conversation. Changes must also be made in the
_init_.pyfile from theswitchdirectory, in thepipeline_manager.pyfile and addcontinue_conversation.py. To be able to use continuous conversation in Hassmic, a switch can be used to choose where to start the pipeline, fromWAKE-WORDor fromSTT-START. In the continue_conversatin switch code, you can set how many seconds to wait for the next command until it switches back to wake word detection. From what I noticed, after 9 seconds it is no longer in the listening state and the pipeline resumes from the start.Because
stt-listeningstarts before the tts message is finished playing, I made an automation in thecontinue_conversation switchcode that mutes the microphone between thetts-speakingandtts-listeningstatuses of thesimple_state sensor. Because I failed to import thesimple_state sensorinternally in thecontinue_conversation switch, I chose to import it from the home assistant, but I think it would work better if you managed to import it directly from the hassmic integration.In pipeline_manager I put
conversation_id=”123456789”and it works fine with OpenAi to retain conversation history for last 20 messages. Maybe we will think of a logic to generate random ids forconversation_idbut keep a specific Id in certain situations if we want to retain the history of the conversation. I believe that the satellite, as in our Hassmic case, is the one that generates theconversation_idand the Home Assistant pipeline takes theconversation_idfrom the satellite.Optionally you can use uith that the
custom_responses blueprintwhich gives an answer after detecting the wake word (Ex: yes i'm listening) or if you sayok nabutwice or when it is incontinue_conversation modeand you don't realize that the satellite is actually waiting for the command and not the wake word.