Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adding timeout to WakeStreamingSatellite event_from_mic to keep it from getting stuck #211

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions wyoming_satellite/satellite.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,10 @@ def __init__(self, settings: SatelliteSettings) -> None:
# wake word id -> seconds
self.refractory_timestamp: Dict[Optional[str], float] = {}

# Timestamp in the future when we will have timed out (set with
# time.monotonic())
self.timeout_seconds: Optional[float] = None

if settings.vad.enabled:
_LOGGER.warning("VAD is enabled but will not be used")

Expand Down Expand Up @@ -1296,6 +1300,25 @@ async def event_from_mic(
if self.stt_audio_writer is not None:
self.stt_audio_writer.write(audio_bytes)

if ( self.is_streaming
and (self.timeout_seconds is not None)
and (time.monotonic() >= self.timeout_seconds)
):
_LOGGER.debug("Streaming timed out, stopping")
# Time out during wake word recognition
self.is_streaming = False
self.timeout_seconds = None

# Stop debug recording
if self.stt_audio_writer is not None:
self.stt_audio_writer.stop()

# Stop pipeline
await self.event_to_server(AudioStop().event())

_LOGGER.info("Waiting for speech")
await self.trigger_streaming_stop()

if self.is_streaming:
# Forward to server
await self.event_to_server(event)
Expand Down Expand Up @@ -1347,6 +1370,17 @@ async def event_from_wake(self, event: Event) -> None:
# No refractory period
self.refractory_timestamp.pop(detection.name, None)

# set our timeout window
if self.settings.vad.wake_word_timeout is not None:
# Set future time when we'll stop streaming if the wake word
# hasn't been detected.
self.timeout_seconds = (
time.monotonic() + self.settings.vad.wake_word_timeout
)
else:
# No timeout
self.timeout_seconds = None

# Forward to the server
await self.event_to_server(event)

Expand Down
Loading