1
私はあなたのinfo.plist
でNSSpeechRecognitionUsageDescription
キーを追加し、あなたが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);
}];
}
}];
}