Add maximum seconds for ringing timer (#261)
Auto stop ringing timer if the determined time (default 15 mins) has passed without manually stopping. This max time can be modified using the command `--timer-max-ring-seconds`.
This commit is contained in:
1 parent
ede3785539
commit
4194aa42ec
3 files changed
+28
-1
No files matched your search
@@ -145,6 +145,12 @@ async def main() -> None:
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Enable thinking finish sound, when the assistant is done thinking and needed more time to process",
|
help="Enable thinking finish sound, when the assistant is done thinking and needed more time to process",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--timer-max-ring-seconds",
|
||||||
|
type=float,
|
||||||
|
default=900.0, # 15 minutes
|
||||||
|
help="Seconds before a ringing timer auto-stops (default: 900)",
|
||||||
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--debug",
|
"--debug",
|
||||||
action="store_true",
|
action="store_true",
|
||||||
@@ -347,6 +353,7 @@ async def main() -> None:
|
|||||||
refractory_seconds=args.refractory_seconds,
|
refractory_seconds=args.refractory_seconds,
|
||||||
download_dir=args.download_dir,
|
download_dir=args.download_dir,
|
||||||
volume=initial_volume,
|
volume=initial_volume,
|
||||||
|
timer_max_ring_seconds=args.timer_max_ring_seconds,
|
||||||
)
|
)
|
||||||
|
|
||||||
if args.enable_thinking_sound:
|
if args.enable_thinking_sound:
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ class ServerState:
|
|||||||
muted: bool = False
|
muted: bool = False
|
||||||
connected: bool = False
|
connected: bool = False
|
||||||
volume: float = 1.0
|
volume: float = 1.0
|
||||||
|
timer_max_ring_seconds: float = 900.0
|
||||||
|
|
||||||
def save_preferences(self) -> None:
|
def save_preferences(self) -> None:
|
||||||
"""Save preferences as JSON."""
|
"""Save preferences as JSON."""
|
||||||
|
|||||||
@@ -152,6 +152,7 @@ class VoiceSatelliteProtocol(APIServer):
|
|||||||
self._tts_played = False
|
self._tts_played = False
|
||||||
self._continue_conversation = False
|
self._continue_conversation = False
|
||||||
self._timer_finished = False
|
self._timer_finished = False
|
||||||
|
self._timer_ring_start: Optional[float] = None
|
||||||
self._processing = False
|
self._processing = False
|
||||||
self._pipeline_active = False
|
self._pipeline_active = False
|
||||||
self._external_wake_words: Dict[str, VoiceAssistantExternalWakeWord] = {}
|
self._external_wake_words: Dict[str, VoiceAssistantExternalWakeWord] = {}
|
||||||
@@ -241,6 +242,7 @@ class VoiceSatelliteProtocol(APIServer):
|
|||||||
if not self._timer_finished:
|
if not self._timer_finished:
|
||||||
self.state.active_wake_words.add(self.state.stop_word.id)
|
self.state.active_wake_words.add(self.state.stop_word.id)
|
||||||
self._timer_finished = True
|
self._timer_finished = True
|
||||||
|
self._timer_ring_start = time.monotonic()
|
||||||
self.duck()
|
self.duck()
|
||||||
self._play_timer_finished()
|
self._play_timer_finished()
|
||||||
|
|
||||||
@@ -416,6 +418,7 @@ class VoiceSatelliteProtocol(APIServer):
|
|||||||
|
|
||||||
if self._timer_finished:
|
if self._timer_finished:
|
||||||
self._timer_finished = False
|
self._timer_finished = False
|
||||||
|
self._timer_ring_start = None
|
||||||
self.unduck()
|
self.unduck()
|
||||||
self.state.tts_player.stop()
|
self.state.tts_player.stop()
|
||||||
_LOGGER.debug("Stopping timer finished sound")
|
_LOGGER.debug("Stopping timer finished sound")
|
||||||
@@ -462,8 +465,24 @@ class VoiceSatelliteProtocol(APIServer):
|
|||||||
if not self._timer_finished:
|
if not self._timer_finished:
|
||||||
_LOGGER.debug("Timer finished sound stopped")
|
_LOGGER.debug("Timer finished sound stopped")
|
||||||
self.unduck()
|
self.unduck()
|
||||||
|
self._timer_ring_start = None
|
||||||
return
|
return
|
||||||
|
|
||||||
|
# Auto-stop after timer_max_ring_seconds
|
||||||
|
if self._timer_ring_start is not None:
|
||||||
|
elapsed = time.monotonic() - self._timer_ring_start
|
||||||
|
if elapsed >= self.state.timer_max_ring_seconds:
|
||||||
|
_LOGGER.info(
|
||||||
|
"Timer auto-stopped after %.0f seconds (max=%.0f)",
|
||||||
|
elapsed,
|
||||||
|
self.state.timer_max_ring_seconds,
|
||||||
|
)
|
||||||
|
self._timer_finished = False
|
||||||
|
self._timer_ring_start = None
|
||||||
|
self.state.active_wake_words.discard(self.state.stop_word.id)
|
||||||
|
self.unduck()
|
||||||
|
return
|
||||||
|
|
||||||
self.state.tts_player.play(
|
self.state.tts_player.play(
|
||||||
self.state.timer_finished_sound,
|
self.state.timer_finished_sound,
|
||||||
done_callback=lambda: call_all(
|
done_callback=lambda: call_all(
|
||||||
|
|||||||
Reference in new issue
Block a user