docs » hs.speech.listener
This module provides access to the Speech Recognizer component of OS X.
The speech recognizer functions and methods provide a way to add commands which may be issued to Hammerspoon through spoken words and phrases to trigger a callback.
- Constructors - API calls which return an object, typically one that offers API methods
- new
- Methods - API calls which can only be made on an object returned by a constructor
- blocksOtherRecognizers
- commands
- delete
- foregroundOnly
- isListening
- setCallback
- start
- stop
- title
Signature | hs.speech.listener.new([title]) -> recognizerObject |
---|---|
Type | Constructor |
Description | Creates a new speech recognizer object for use by Hammerspoon. |
Parameters |
|
Returns |
|
Notes |
|
| Signature | hs.speech.listener:blocksOtherRecognizers([flag]) -> recognizerObject | current value
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set whether or not the speech recognizer should block other recognizers when it is active. |
| Parameters |
- flag - an optional boolean indicating whether or not the speech recognizer should block other speech recognizers when it is active. Defaults to false.
- If no parameter is provided, returns the current value; otherwise returns the recognizer object.
| Signature | hs.speech.listener:commands([commandsArray]) -> recognizerObject | current value
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set the commands this speech recognizer will listen for. |
| Parameters |
- commandsArray - an optional array of strings which specify the commands the recognizer will listen for.
- If no parameter is provided, returns the current value; otherwise returns the recognizer object.
- The list of commands will appear in the Dictation Commands window, if it is visible, under the title of this speech recognizer. The text of each command is a possible value which may be sent as the second argument to a callback function for this speech recognizer, if one is defined.
- Setting this to an empty list does not disable the speech recognizer, but it does make it of limited use, other than to provide a title in the Dictation Commands window. To disable the recognizer, use the
hs.speech.listener:stop
orhs.speech.listener:delete
methods.
Signature | hs.speech.listener:delete() -> recognizerObject |
---|---|
Type | Method |
Description | Disables the speech recognizer and removes it from the possible available speech recognizers. |
Parameters |
|
Returns |
|
Notes |
|
| Signature | hs.speech.listener:foregroundOnly([flag]) -> recognizerObject | current value
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set whether or not the speech recognizer is active only when the Hammerspoon application is active. |
| Parameters |
- flag - an optional boolean indicating whether or not the speech recognizer should respond to commands only when Hammerspoon is the active application or not. Defaults to true.
- If no parameter is provided, returns the current value; otherwise returns the recognizer object.
Signature | hs.speech.listener:isListening() -> boolean |
---|---|
Type | Method |
Description | Returns a boolean value indicating whether or not the recognizer is currently enabled (started). |
Parameters |
|
Returns |
|
Signature | hs.speech.listener:setCallback(fn) -> recognizerObject |
---|---|
Type | Method |
Description | Sets or removes a callback function for the speech recognizer. |
Parameters |
|
Returns |
|
Notes |
|
Signature | hs.speech.listener:start() -> recognizerObject |
---|---|
Type | Method |
Description | Make the speech recognizer active. |
Parameters |
|
Returns |
|
Signature | hs.speech.listener:stop() -> recognizerObject |
---|---|
Type | Method |
Description | Disables the speech recognizer. |
Parameters |
|
Returns |
|
Notes |
|
| Signature | hs.speech.listener:title([title]) -> recognizerObject | current value
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Method |
| Description | Get or set the title for a speech recognizer. |
| Parameters |
- title - an optional parameter specifying the title under which commands assigned to this speech recognizer will be listed in the Dictation Commands display when it is visible. If you provide an explicit
nil
, it will reset to the default of "Hammerspoon".
- If no parameter is provided, returns the current value; otherwise returns the recognizer object.