iOS Is Speech Recognition Permission Mandatory?

I am using speech recognition for search any object with user's voice. My code is below. But I realize that some Apple Market apps which are using speech recognizer (not sure their technology), they don't need to get speech recognizer permission to do this. But my code is getting permission and the permission is like that

"[AppName] would like to access speech recognition. Speech data from this app will be sent to Apple to process your requests. This will also help Apple improve its speech recognition technology."

which can be disruptive for the user. Do you have any idea? I don't want to ask permission.

audioEngine = [[AVAudioEngine alloc] init];

if (recognitionTask) {
    [recognitionTask cancel];
    recognitionTask = nil;
}

NSError *error;
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryRecord error:&error];
[audioSession setActive:YES withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error];

if (@available(iOS 10.0, *)) {
    recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
} else {}

AVAudioInputNode *inputNode = audioEngine.inputNode;
recognitionRequest.shouldReportPartialResults = YES;
if (@available(iOS 10.0, *)) {
    recognitionTask = [speechRecognizer recognitionTaskWithRequest:recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error){
        BOOL isFinal = isSpeechStop;
        if (!isFinal) {
            NSLog(@"RESULT:%@",result.bestTranscription.formattedString);
           isFinal = !result.isFinal;
            }
        }
        if (error || isFinal) {
            [audioEngine stop];
            [inputNode removeTapOnBus:0];
            recognitionRequest = nil;
            [recognitionTask cancel];
            recognitionTask = nil;

        }
}

AVAudioFormat *recordingFormat = [inputNode outputFormatForBus:0];
[inputNode installTapOnBus:0 bufferSize:1024 format:recordingFormat block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
    [recognitionRequest appendAudioPCMBuffer:buffer];
}];

[audioEngine prepare];
[audioEngine startAndReturnError:&error];

If you don't want to ask user for permission, you'll need to use a 3rd party SDK. I don't want to specifically promote any, so I won't mention the SDKs by name. They're quite easy to find via a search.

They'll need microphone permission, of course.

链接地址: http://www.djcxy.com/p/34392.html

上一篇: 语音到文本转换语言模型?

下一篇: iOS是语音识别权限强制性的吗?