Skip to content

Commit

Permalink
refactor/drop_confirmation_state
Browse files Browse the repository at this point in the history
closes #107
  • Loading branch information
JarbasAl committed Jun 19, 2024
1 parent d80eeb7 commit 126764a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
18 changes: 1 addition & 17 deletions ovos_dinkum_listener/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@ def register_event_handlers(self):
self.bus.on("opm.ww.query", self._handle_opm_ww_query)
self.bus.on("opm.vad.query", self._handle_opm_vad_query)

self.bus.on("mycroft.audio.play_sound.response", self._handle_sound_played)

# tracking volume for fake barge-in
self.bus.on("volume.set.percent", self._handle_volume_change)
self.bus.on("mycroft.volume.increase", self._handle_volume_change)
Expand Down Expand Up @@ -619,10 +617,6 @@ def _hotword_audio(self, audio_bytes: bytes, ww_context: dict):
self.bus.emit(Message("mycroft.audio.play_sound",
{"uri": sound, "force_unmute": True},
context))
if not listener.get("instant_listen"):
self.voice_loop.state = ListeningState.CONFIRMATION
self.voice_loop.confirmation_event.clear()
Timer(0.5, lambda: self.voice_loop.confirmation_event.set()).start()

if listen:
msg_type = "recognizer_loop:wakeword"
Expand Down Expand Up @@ -788,12 +782,7 @@ def _handle_listen(self, message: Message):
}
message = message or Message("", context=context) # might be None
self.bus.emit(message.forward("mycroft.audio.play_sound", {"uri": sound}))
if not self.config["listener"].get("instant_listen"):
self.voice_loop.state = ListeningState.CONFIRMATION
self.voice_loop.confirmation_event.clear()
Timer(0.5, lambda: self.voice_loop.confirmation_event.set()).start()
else:
self.voice_loop.state = ListeningState.BEFORE_COMMAND
self.voice_loop.state = ListeningState.BEFORE_COMMAND
else:
self.voice_loop.state = ListeningState.BEFORE_COMMAND

Expand Down Expand Up @@ -877,11 +866,6 @@ def _handle_wake_up(self, message: Message):
LOG.debug("SLEEP - wake up triggered from bus event")
self.voice_loop.wakeup()

def _handle_sound_played(self, message: Message):
"""Handle response message from audio service."""
if self.voice_loop.state == ListeningState.CONFIRMATION:
self.voice_loop.confirmation_event.set()

def _handle_b64_audio(self, message: Message):
""" transcribe base64 encoded audio """
b64audio = message.data["audio"]
Expand Down
14 changes: 2 additions & 12 deletions ovos_dinkum_listener/voice_loop/voice_loop.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class ListeningState(str, Enum):
SLEEPING = "sleeping"
CHECK_WAKE_UP = "wake_up"

CONFIRMATION = "confirmation"

BEFORE_COMMAND = "before_cmd"
IN_COMMAND = "in_cmd"
AFTER_COMMAND = "after_cmd"
Expand Down Expand Up @@ -248,13 +246,6 @@ def run(self):
self._before_wakeup(chunk)
elif self.state == ListeningState.CHECK_WAKE_UP:
self._detect_wakeup(chunk)

# set either by timeout (0.5) or by ovos-audio response
elif self.state == ListeningState.CONFIRMATION and \
self.confirmation_event.is_set():
self.state = ListeningState.BEFORE_COMMAND
LOG.debug(f"STATE: {self.state}")

elif self.state == ListeningState.BEFORE_COMMAND:
LOG.debug("waiting for speech")
self._before_cmd(chunk)
Expand Down Expand Up @@ -507,9 +498,8 @@ def _detect_ww(self, chunk: bytes) -> bool:
LOG.debug(f"STATE: {self.state}")
else:
# Wake word detected, begin recording voice command
if not self.state == ListeningState.CONFIRMATION:
self.state = ListeningState.BEFORE_COMMAND
LOG.debug(f"STATE: {self.state}")
self.state = ListeningState.BEFORE_COMMAND
LOG.debug(f"STATE: {self.state}")
self.reset_speech_timer()
self.stt_audio_bytes = bytes()
self.stt.stream_start()
Expand Down
3 changes: 0 additions & 3 deletions test/unittests/test_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,9 +294,6 @@ def test_handle_listen(self):
self.assertEqual(self.service.voice_loop.stt_audio_bytes, bytes())
self.service.voice_loop.stt.stream_start.assert_called_once()
self.service.voice_loop.stt.stream_start.reset_mock()
self.assertEqual(self.service.voice_loop.state, ListeningState.CONFIRMATION)
sleep(1)
self.assertEqual(self.service.voice_loop.confirmation_event.is_set(), True)

self.service.voice_loop.state = ListeningState.DETECT_WAKEWORD
self.service.config["confirm_listening"] = False
Expand Down

0 comments on commit 126764a

Please sign in to comment.