Skip to content

Commit 9456dea

Browse files
FireChickenProductivitypre-commit-ci[bot]nriley
authored
Add deeper sleep support (talonhub#1813)
Add a tag for enabling sleep with a longer wakeup command --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Nicholas Riley <[email protected]>
1 parent 8a23fc7 commit 9456dea

File tree

7 files changed

+92
-37
lines changed

7 files changed

+92
-37
lines changed

core/modes/deep_sleep.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
from talon import Context, Module, actions
2+
3+
mod = Module()
4+
mod.tag(
5+
"deep_sleep",
6+
desc="Tag for enabling deep sleep, requiring a longer wakeup command (defined in `sleep_mode_deep.talon`)",
7+
)
8+
9+
ctx = Context()
10+
11+
12+
@mod.action_class
13+
class Actions:
14+
def deep_sleep_enable():
15+
"""Enable deep sleep.
16+
17+
Deep sleep requires a longer wakeup command to exit sleep
18+
mode, helping prevent unintended wakeups from conversations,
19+
meetings, listening to videos, etc.
20+
21+
Instead of invoking this action directly, consider enabling
22+
the `user.deep_sleep` tag in applications where unwanted
23+
wakeups are more likely or problematic, such as meeting
24+
apps. With this tag active, any sleep command triggers deep
25+
sleep.
26+
27+
You can also manually activate deep sleep by defining a custom
28+
voice command using this action.
29+
30+
Note: If the user.deep_sleep_disable action is not used to
31+
wake up from deep sleep, then the deep sleep tag will stay
32+
active.
33+
34+
"""
35+
ctx.tags = ["user.deep_sleep"]
36+
actions.speech.disable()
37+
38+
def deep_sleep_disable():
39+
"""Disable deep sleep"""
40+
ctx.tags = []
41+
actions.speech.enable()

core/modes/modes_not_dragon.talon

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ not speech.engine: dragon
1515
# because it's part of the rule definition, but "hey bob" will be ignored, because
1616
# we don't do anything with the <phrase> in the body of the command.
1717

18-
^talon wake [<phrase>]$: speech.enable()
19-
20-
# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon,
21-
# "wake up" is used to specifically control Dragon, and not affect Talon.
22-
#
23-
# It's a useful and well known command, though, so if you're using any other speech
24-
# engine, this controls Talon.
25-
^(wake up)+$: speech.enable()
26-
2718
# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon,
2819
# "go to sleep" is used to specifically control Dragon, and not affect Talon.
2920
#

core/modes/sleep_mode.talon

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,30 +7,3 @@ settings():
77
user.mouse_enable_pop_click = 0
88
# Stop mouse scroll down using hiss noise
99
user.mouse_enable_hiss_scroll = false
10-
11-
#================================================================================
12-
# Commands to wake Talon
13-
#================================================================================
14-
15-
# Note: these have repeaters on them (+) to work around an issue where, in sleep mode,
16-
# you can get into a situation where these commands are difficult to trigger.
17-
18-
# These commands are fully anchored (^ and $), which means that there must be
19-
# silence before and after saying them in order for them to recognize (this reduces
20-
# false positives during normal sleep mode, normally a good thing).
21-
22-
# However, ignored background speech during sleep mode also counts as an utterance.
23-
24-
# Thus, if you say "blah blah blah talon wake", these won't trigger, because "blah
25-
# blah blah" was part of the same utterance. You have to say "blah blah blah" <pause,
26-
# wait for speech timeout>, "talon wake" <pause, wait for speech timeout>.
27-
28-
# Sometimes people would forget the second pause, notice things weren't working, and
29-
# say "talon wake" over and over again before the speech timeout ever gets hit, which
30-
# means that these won't recognize. The (+) handles this case, so if you say
31-
# <pause> "talon wake talon wake" <pause>, it'll still work.
32-
33-
^(welcome back)+$:
34-
user.mouse_wake()
35-
user.history_enable()
36-
user.talon_mode()

core/modes/sleep_mode_deep.talon

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
mode: sleep
2+
tag: user.deep_sleep
3+
-
4+
5+
^wake up and listen$: user.deep_sleep_disable()

core/modes/modes_dragon.talon renamed to core/modes/sleep_mode_dragon.talon

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ speech.engine: dragon
1313
# because it's part of the rule definition, but "hey bob" will be ignored, because
1414
# we don't do anything with the <phrase> in the body of the command.
1515
^talon sleep [<phrase>]$: speech.disable()
16-
^talon wake [<phrase>]$: speech.enable()
1716

1817
^sleep all [<phrase>]$:
1918
user.switcher_hide_running()
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
mode: command
2+
mode: dictation
3+
mode: sleep
4+
not speech.engine: dragon
5+
not tag: user.deep_sleep
6+
-
7+
8+
# We define this *only* if the speech engine isn't Dragon, because if you're using Dragon,
9+
# "wake up" is used to specifically control Dragon, and not affect Talon.
10+
#
11+
# It's a useful and well known command, though, so if you're using any other speech
12+
# engine, this controls Talon.
13+
14+
^(wake up)+$: speech.enable()

core/modes/sleep_mode_wakeup.talon

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
mode: sleep
2+
not tag: user.deep_sleep
3+
-
4+
5+
#================================================================================
6+
# Commands to wake Talon
7+
#================================================================================
8+
9+
# Note: these have repeaters on them (+) to work around an issue where, in sleep mode,
10+
# you can get into a situation where these commands are difficult to trigger.
11+
12+
# These commands are fully anchored (^ and $), which means that there must be
13+
# silence before and after saying them in order for them to recognize (this reduces
14+
# false positives during normal sleep mode, normally a good thing).
15+
16+
# However, ignored background speech during sleep mode also counts as an utterance.
17+
18+
# Thus, if you say "blah blah blah talon wake", these won't trigger, because "blah
19+
# blah blah" was part of the same utterance. You have to say "blah blah blah" <pause,
20+
# wait for speech timeout>, "talon wake" <pause, wait for speech timeout>.
21+
22+
# Sometimes people would forget the second pause, notice things weren't working, and
23+
# say "talon wake" over and over again before the speech timeout ever gets hit, which
24+
# means that these won't recognize. The (+) handles this case, so if you say
25+
# <pause> "talon wake talon wake" <pause>, it'll still work.
26+
27+
^(welcome back)+$:
28+
user.mouse_wake()
29+
user.history_enable()
30+
user.talon_mode()
31+
32+
^talon wake [<phrase>]$: speech.enable()

0 commit comments

Comments
 (0)