Skip to content

Commit 32b0758

Browse files
📝 Add docstrings to JarbasAl-patch-1 (#72)
Docstrings generation was requested by @JarbasAl. * #71 (comment) The following files were modified: * `__init__.py` Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: JarbasAI <33701864+JarbasAl@users.noreply.github.com>
1 parent 37dc9f0 commit 32b0758

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

__init__.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ def initialize(self):
4242

4343
@property
4444
def default_listen_mode(self):
45+
"""
46+
Determine the default listener mode from the configuration.
47+
48+
Selects 'continuous' when the listener's `continuous_listen` setting is true, otherwise selects 'hybrid' when `hybrid_listen` is true, and falls back to 'wakeword' if neither is enabled.
49+
50+
Returns:
51+
str: One of 'continuous', 'hybrid', or 'wakeword' indicating the default listening mode.
52+
"""
4553
listener_config = Configuration().get("listener", {})
4654
if listener_config.get("continuous_listen", False):
4755
return "continuous"
@@ -51,12 +59,34 @@ def default_listen_mode(self):
5159
return "wakeword"
5260

5361
def is_dictating(self, sess) -> bool:
62+
"""
63+
Check whether dictation is active for the given session.
64+
65+
Parameters:
66+
sess: The session object whose dictation state should be checked.
67+
68+
Returns:
69+
True if the session currently has an active dictation, False otherwise.
70+
"""
5471
if sess.session_id in self.dictation_sessions:
5572
return self.dictation_sessions[sess.session_id].get("dictating", False)
5673
return False
5774

5875
@adds_context("DictationKeyword", "dictation")
5976
def start_dictation(self, message=None):
77+
"""
78+
Begin a dictation session for the current conversation session.
79+
80+
Creates or updates an entry in self.dictation_sessions for the session returned by SessionManager.get(message) with:
81+
- file_name taken from message.data["name"] if present, otherwise the current timestamp,
82+
- dictating set to True,
83+
- an empty dictation_stack.
84+
85+
Also emits a bus message to set the recognizer loop mode to "continuous".
86+
87+
Parameters:
88+
message (Message, optional): Incoming message whose .data may contain a "name" key to use as the dictation file name. If omitted, a default Message is used.
89+
"""
6090
message = message or Message("")
6191
sess = SessionManager.get(message)
6292
self.dictation_sessions[sess.session_id] = dict(
@@ -87,6 +117,14 @@ def stop_dictation(self, message=None):
87117

88118
@intent_handler("start_dictation.intent")
89119
def handle_start_dictation_intent(self, message):
120+
"""
121+
Handle the user intent to begin dictation for the current session.
122+
123+
Speaks a confirmation dialog ("start") if dictation is not already active for the session, or an "already_dictating" dialog if it is, then enables dictation listening for the session.
124+
125+
Parameters:
126+
message: Bus message containing the intent payload and session information.
127+
"""
90128
sess = SessionManager.get(message)
91129
if not self.is_dictating(sess):
92130
self.speak_dialog("start", wait=True)
@@ -96,6 +134,14 @@ def handle_start_dictation_intent(self, message):
96134

97135
@intent_handler("stop_dictation.intent")
98136
def handle_stop_dictation_intent(self, message):
137+
"""
138+
Handle a stop-dictation intent by notifying the user and stopping any active dictation.
139+
140+
If there is no active dictation for the session, speaks the "stop" dialog; otherwise speaks "not_dictating". Always invokes stop_dictation to ensure dictation is terminated and saved as appropriate.
141+
142+
Parameters:
143+
message: The incoming intent message containing session and intent data.
144+
"""
99145
sess = SessionManager.get(message)
100146
if not self.is_dictating(sess):
101147
self.speak_dialog("stop")

0 commit comments

Comments
 (0)