NSSpeechRecognizer Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/AppKit.framework |
| Availability | Available in OS X v10.3 and later. |
| Companion guide | |
| Declared in | NSSpeechRecognizer.h |
Overview
The NSSpeechRecognizer class is the Cocoa interface to Speech Recognition on OS X. Speech Recognition is architected as a “command and control” voice recognition system. It uses a finite state grammar and listens for phrases in that grammar. When it recognizes a phrase, it notifies the client process. This architecture is different from that used to support dictation.
Through an NSSpeechRecognizer instance, Cocoa applications can use the speech recognition engine built into OS X to recognize spoken commands. With speech recognition, users can accomplish complex, multi-step tasks with one spoken command—for example, “schedule a meeting with Adam and John tomorrow at ten o’clock.”
The NSSpeechRecognizer class has methods that let you specify which spoken words should be recognized as commands (setCommands:) and to start and stop listening (startListening and stopListening). When the Speech Recognition facility recognizes one of the designated commands, NSSpeechRecognizer invokes the delegation method speechRecognizer:didRecognizeCommand:, allowing the delegate to perform the command.
Speech Recognition is just one of the OS X speech technologies. The Speech Synthesis technology allows applications to “pronounce” written text in U.S. English; the NSSpeechSynthesizer class is the Cocoa interface to this technology. These technologies provide benefits for all users, and are particularly useful to those users who have difficulties seeing the screen or using the mouse and keyboard. By incorporating speech into your application, you can provide a concurrent mode of interaction for your users: In OS X, your software can accept input and provide output without requiring users to change their working context.
Tasks
Creating Speech Recognizers
Configuring Speech Recognizers
-
– commands -
– setCommands: -
– displayedCommandsTitle -
– setDisplayedCommandsTitle: -
– listensInForegroundOnly -
– setListensInForegroundOnly: -
– blocksOtherRecognizers -
– setBlocksOtherRecognizers: -
– delegate -
– setDelegate:
Listening
Instance Methods
blocksOtherRecognizers
Returns whether the receiver should block all other recognizers (that is, other applications attempting to understand spoken commands) when listening.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hcommands
Returns an array of strings defining the commands for which the receiver should listen.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hdelegate
Returns the receiver’s delegate.
Return Value
The receiver’s delegate.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hdisplayedCommandsTitle
Returns the title of the commands section or nil if there is no title.
Discussion
Commands are displayed in the Speech Commands window indented under a section with this title.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hinit
Initializes and returns an instance of the NSSpeechRecognizer class.
Discussion
Returns nil if initialization did not succeed.
Availability
- Available in OS X v10.3 and later.
Declared In
NSSpeechRecognizer.hlistensInForegroundOnly
Returns whether the receiver should only enable its commands when the receiver’s application is the frontmost one.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hsetBlocksOtherRecognizers:
Sets whether the receiver’s commands should be the only enabled commands on the system.
Discussion
If flag is YES, all other speech recognition commands on the system are disabled until the receiver object is released, listening is stopped, or this method is called again with flag as NO. Because this option effectively takes over the computer at the expense of other applications using speech recognition, you should use it only in circumstances that warrant it, such as when listening for a response important to overall system operation or when an application is running in full-screen mode (such as games and presentation software). The default is NO.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hsetCommands:
Sets the list of commands for which the receiver should listen to commands.
Discussion
If the receiver is already listening, the current command list is updated and listening continues. commands should be an array of NSString objects. The commands must be in U.S. English.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hsetDelegate:
Sets the receiver’s delegate.
Parameters
- anObject
The delegate to set as the receiver’s. The delegate must conform to the
NSSpeechRecognizerDelegate Protocolprotocol.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hsetDisplayedCommandsTitle:
Sets whether the speech-recognition commands should be displayed indented under a section title in the Speech Commands window, and if so, sets the title string to display.
Discussion
When title is a non-empty string, the receiver’s commands are displayed under a section with title. If title is nil or an empty string, the commands are displayed at the top level of the Speech Commands window. This default is not to display the commands under a section title.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hsetListensInForegroundOnly:
Sets whether the receiver should only enable its commands when the receiver’s application is the frontmost one.
Discussion
If flag is YES, the receiver’s commands are only recognized when the receiver’s application is the frontmost application—normally the application displaying the menu bar. If flag is NO, the commands are recognized regardless of the visibility of applications, including agent applications (agent applications, which have the LSUIElement property set, do not appear in the Dock or Force Quit window). The default is YES.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.hstartListening
Tells the speech recognition engine to begin listening for commands.
Discussion
When a command is recognized the message speechRecognizer:didRecognizeCommand: is sent to the delegate.
Availability
- Available in OS X v10.3 and later.
See Also
Declared In
NSSpeechRecognizer.h© 2009 Apple Inc. All Rights Reserved. (Last updated: 2009-04-22)