|Type||Topic||Plugin||Version||macOS||Windows||Linux||Console & Web||iOS|
|class||SpeechRecognition||MBS MacFrameworks Plugin||19.4||Yes||No||No||Yes, macOS only||No|
An SFSpeechRecognizerMBS object is the central object for managing the speech recognizer process. Use this object to:
- Request authorization to use speech recognition services.
- Specify the language to use during the recognition process.
- Initiate new speech recognition tasks.
Set Up Speech Recognition
Each speech recognizer supports only one language, which you specify at creation time. The successful creation of a speech recognizer does not guarantee that speech recognition services are available. For some languages, the recognizer might require an Internet connection. Use the available property to find out if speech recognition services are available for the current language.
To initiate the speech recognition process, do the following:
- Request authorization to use speech recognition.
- Create an SFSpeechRecognizerMBS object.
- Verify the availability of services using the available property of your speech recognizer object.
- Prepare your audio content.
- Create a recognition request object—an object that descends from SFSpeechRecognitionRequest.
- Call the recognitionTaskWithRequest method to begin the recognition process.
The type of recognition request object you create depends on whether you are processing an existing audio file or an incoming stream of audio. For existing audio files, create a SFSpeechURLRecognitionRequestMBS object. For audio streams, create a SFSpeechAudioBufferRecognitionRequestMBS object.
Create a Great User Experience for Speech Recognition
Here are some tips to consider when adding speech recognition support to your app.
- Be prepared to handle failures caused by speech recognition limits. Because speech recognition is a network-based service, limits are enforced so that the service can remain freely available to all apps. Individual devices may be limited in the number of recognitions that can be performed per day, and each app may be throttled globally based on the number of requests it makes per day. If a recognition request fails quickly (within a second or two of starting), check to see if the recognition service became unavailable. If it is, you may want to ask users to try again later.
- Plan for a one-minute limit on audio duration. Speech recognition places a relatively high burden on battery life and network usage. To minimize this burden, the framework stops speech recognition tasks that last longer than one minute. This limit is similar to the one for keyboard-related dictation.
- Remind the user when your app is recording. For example, display a visual indicator and play sounds at the beginning and end of speech recognition to help users understand that they're being actively recorded. You can also display speech as it is being recognized so that users understand what your app is doing and see any mistakes made during the recognition process.
- Do not perform speech recognition on private or sensitive information. Some speech is not appropriate for recognition. Don't send passwords, health or financial data, and other sensitive speech for recognition.
Requires MacOS 10.15 or later.
- 7 events
- event availabilityDidChange(available as Boolean)
- event didDetectSpeech(task as SFSpeechRecognitionTaskMBS)
- event TaskDidFinishRecognition(task as SFSpeechRecognitionTaskMBS, recognitionResult as SFSpeechRecognitionResultMBS)
- event TaskDidFinishSuccessfully(task as SFSpeechRecognitionTaskMBS, successfully as boolean)
- event TaskDidHypothesizeTranscription(task as SFSpeechRecognitionTaskMBS, transcription as SFTranscriptionMBS)
- event TaskFinishedReadingAudio(task as SFSpeechRecognitionTaskMBS)
- event TaskWasCancelled(task as SFSpeechRecognitionTaskMBS)
- 5 properties
- 5 methods
- method Constructor
- method Constructor(locale as NSLocaleMBS)
- method Destructor
- method recognitionTaskWithRequest(request as SFSpeechRecognitionRequestMBS) as SFSpeechRecognitionTaskMBS
- method recognitionTaskWithRequest(request as SFSpeechRecognitionRequestMBS, delegateHandler as recognitionTaskWithRequestCompletedMBS, tag as Variant = nil) as SFSpeechRecognitionTaskMBS
- 4 shared methods
- 2 delegates
- 4 constants
The user granted your app's request to perform speech recognition.
The user denied your app's request to perform speech recognition.
The app's authorization status has not yet been determined.
The device prevents your app from performing speech recognition.
This class has no sub classes.
Some examples which use this class:
The items on this page are in the following plugins: MBS MacFrameworks Plugin.
MBS Xojo blog