【发布时间】:2016-09-28 15:08:29
【问题描述】:
我尝试如下使用语音识别
- (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);
}];
}
}];
}
【问题讨论】:
标签: ios objective-c speech-recognition ios10