listening_timeout
The community/plugin/listening_timeout
directory contains code that implements a timeout for speech recognition. If no speech is detected for a configurable period of time, speech recognition will be disabled.
The main logic for this functionality is in the listening_timeout.py
file.
Here's a breakdown of how it works:
- Settings: The module exposes two settings:
listening_timeout_minutes
(an integer that specifies the timeout in minutes) andlistening_timeout_show_notification
(a boolean that, if enabled, causes a notification to be displayed when the timeout is triggered). - Timeout Trigger: The
SpeechActions.enable()
andpost_phrase()
functions are used to start and reset the timeout timer usingcron.after()
which callscheck_timeout()
when the timer expires.SpeechActions.enable()
is called when speech recognition is enabled.post_phrase()
is called after Talon recognizes a phrase. - Timeout Logic: The
check_timeout()
function checks if the timeout has expired by comparing the last phrase time to the current time. If the timeout has expired,UserActions.listening_timeout_expired()
is called which disables speech recognition and may display a notification if thelistening_timeout_show_notification
setting is enabled. - Notification: The
show_notification()
function displays a notification usingactions.app.notify()
when the timeout expires and thelistening_timeout_show_notification
setting is enabled. - Initialization: When the Talon app starts and is ready, the
on_ready()
function initializes thelast_phrase_time
and starts the timeout job if speech is enabled. It also registers thepost_phrase()
function so it will be called after every phrase.
In summary, listening_timeout.py
adds a speech timeout feature to Talon that disables speech recognition after a period of inactivity and provides a notification when the timeout is reached. This can help prevent Talon from unintentionally interpreting ambient sounds as speech, while enabling automatic re-enabling of speech recognition whenever a phrase is recognized.