2016-09-28 124 views
1

我尝试使用语音识别如下10 IOS语音识别API:错误域= kAFAssistantErrorDomain代码= 1101

- (void)viewDidLoad { 

    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    [self startRecognizer]; 
} 

- (void)startRecognizer { 

    [SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) { 
     if (status == SFSpeechRecognizerAuthorizationStatusAuthorized) 
     { 
     SFSpeechRecognizer *sf =[[SFSpeechRecognizer alloc] init]; 
     NSURL *mp3Path = [[NSBundle bundleForClass:[self class]] URLForResource:@"test" withExtension:@"mp3"]; 
     SFSpeechURLRecognitionRequest *speechRequest = [[SFSpeechURLRecognitionRequest alloc]initWithURL:mp3Path]; 
     [sf recognitionTaskWithRequest:speechRequest resultHandler:^(SFSpeechRecognitionResult * _Nullable result, NSError * _Nullable error) { 
      NSString * translatedString = [[[result bestTranscription] formattedString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; 

      NSLog(@"%@",translatedString); 
     }]; 
     } 
    }]; 
} 

回答

0

info.plist添加NSSpeechRecognitionUsageDescription键,如果你是在simulator测试运行在设备项目。你需要运行ios10的ios真实设备来测试这个!

您可以参考hackingwithswift's arcticle了解更多详情!