经典三段论
SFSpeechRecognizer *recognizer = [[SFSpeechRecognizer alloc] initWithLocale:[NSLocale localeWithLocaleIdentifier:@"zh_CN"]];
NSURL *aURL = [NSURL fileURLWithPath:url];
SFSpeechURLRecognitionRequest *request = [[SFSpeechURLRecognitionRequest alloc] initWithURL:aURL];
[recognizer recognitionTaskWithRequest:request resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
if (error) {
NSLog(@"reconize speech error : %@", error);
}
NSLog(@"speech text : %@", result.bestTranscription.formattedString);
}];
注意:需在info.plist中设置Privacy - Speech Recognition Usage Description键,否则崩溃