iOS开发 Speech-Kit 语音识别内容如下:
授权:
[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
if (status == 3) {
NSLog(@"授权成功");
}
else {
NSLog(@"授权失败");
}
}];
创建对象:
NSLocale *loc = [NSLocale localeWithLocaleIdentifier:_localStr ? _localStr : @"zh-CN"]; // zh-CN ja-JP
// 创建语音识别操作类对象
SFSpeechRecognizer *rec = [[SFSpeechRecognizer alloc] initWithLocale:loc];
进行识别:
SFSpeechRecognitionRequest *request = [[SFSpeechURLRecognitionRequest alloc] initWithURL:url];
// 进行请求
[rec recognitionTaskWithRequest:request resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
NSLog(@"%@", result.bestTranscription.formattedString);
}];