The NSSpeechRecognizer class is the Cocoa interface to Speech Recognition in macOS. This class provides a “command and control” style of voice recognition system, where the command phrases must be defined prior to listening, in contrast to a dictation system where the recognized text is unconstrained.
Language
- Swift
- Objective-C
SDK
- macOS 10.10+
Overview
Through an NSSpeechRecognizer instance, Cocoa applications can use the speech recognition engine built into macOS to recognize spoken commands. With speech recognition, users can accomplish complex tasks with spoken commands—for example, “Move pawn B2 to B4” and “Take back move.”
The NSSpeechRecognizer class has a property that lets you specify which spoken words should be recognized as commands (commands) and methods that let you 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 macOS speech technologies. The Speech Synthesis technology allows applications to “pronounce” written text in U.S. English and over 25 other languages, with a number of different voices and dialects for each language (NSSpeechSynthesizer is the Cocoa interface to this technology). Both speech 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 macOS, your software can accept input and provide output without requiring users to change their working context.