2016-09-28 18 views
1

私はあなたのinfo.plistNSSpeechRecognitionUsageDescriptionキーを追加し、あなたがsimulatorでテストしている場合、デバイスでこのプロジェクトを実行IOS 10音声認識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

以下のように音声認識を使用してみてください。これをテストするには、ios10を実行する必要があります。

詳しくは、hackingwithswift's arcticleを参照してください。