美文网首页iOS Developer
iOS 10 Speech Recognition

iOS 10 Speech Recognition

作者: iOS104 | 来源:发表于2017-03-23 20:01 被阅读131次

IOS10.0系统新增了Speech,语音识别的API

  • 下面是一个简单的demo,可以从视频中读取语音,然后进行语音识别,然后以字幕的形式显示出来。
11.gif

github地址

  • 首先获取权限,苹果对权限安全这一面是做了很大的改进的,通过iOS10关于权限的新特性不难看出来
Paste_Image.png

语音识别需要加上Privacy - Speech Recognition Usage Description

[SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
        if (status == SFSpeechRecognizerAuthorizationStatusAuthorized) {
            NSLog(@"获取语音识别权限成功");
        }
 }];
  • Speech 具有连续的语音识别、对语音文件以及语音流的识别、并且支持多语言的听写
_recognitionRequest = [[SFSpeechAudioBufferRecognitionRequest alloc] init];
    // zh_cn en-US
    _speechRecognizer = [[SFSpeechRecognizer alloc] initWithLocale:[[NSLocale alloc] initWithLocaleIdentifier:@"en-US"]];
    
    WEAKSELF_AT
    _recognitionTask = [_speechRecognizer recognitionTaskWithRequest:_recognitionRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) {
        
        weakSelf_AT.label.text = result.bestTranscription.formattedString;
        
        if (result.isFinal) {
            weakSelf_AT.recognitionTask = nil;
            weakSelf_AT.recognitionRequest = nil;
        }
    }];
  • 主要类
Paste_Image.png

相关文章

网友评论

    本文标题:iOS 10 Speech Recognition

    本文链接:https://www.haomeiwen.com/subject/cpvtottx.html