简体   繁体   中英

Is it possible to limit SFSpeechRecognizer's vocabulary?

I'd like to use the ios SFSpeechRecognizer to recognize a closed set of words and phrases. Is there a way to specify these and remove all other possibilities? I cannot seem to find a way to do this.

I think you cannot limit SFSpeechRecognizer 's vocabulary, but you can fire action only if the words you want are recognized.

When you get your output, you can try something like this:

self.recognitionTask = speechRecognizer?.recognitionTask(with: recognitionRequest, resultHandler: { (result, error) in
    if result == "Desired word one" {
        // Do something
    } else if result == "Desired word two" {
        // Do something else
    } else {
        // Don't do anything
    }
})

You can try to use contextualStrings property of SFSpeechAudioBufferRecognitionRequest to set high priority or to set some words that are not in vocabulary. For more info look here: https://developer.apple.com/documentation/speech/sfspeechrecognitionrequest/1649391-contextualstrings?language=objc

  SFSpeechAudioBufferRecognitionRequest *recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
    recognitionRequest.contextualStrings = @[@"Your specific word", @"short custom phrases that are unique to your app"];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM