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);
}];
本文详细介绍了在iOS应用中使用Speech-Kit进行语音识别的方法,包括授权流程、语音识别对象的创建及识别过程,提供了完整的代码示例。
666

被折叠的 条评论
为什么被折叠?



