简单的 NSSpeechRecognizer 代码,不起作用!
我注意到 ADC 库中的 NSSpeechRecognizer,我发现它非常有趣,因此为了使用它,我准备了一个简单的应用程序,它只会监听命令,如果识别到它,它会在日志中显示它。
使用的代码是:
- (id)init {
if (self = [super init]) {
// Insert code here to initialize your application
NSArray *cmds = [NSArray arrayWithObjects:@"A",@"B", @"C",@"alpha",@"beta",@"vodka",@"wine",nil];
recog = [[NSSpeechRecognizer alloc] init]; // recog is an ivar
[recog setCommands:cmds];
[recog setDelegate:self];
}
return self;
}
- (IBAction)listen:(id)sender
{ NSLog(@"listen:");
if ([sender state] == NSOnState) { // listen
[recog startListening];
} else {
[recog stopListening];
}
}
- (void)speechRecognizer:(NSSpeechRecognizer *)sender didRecognizeCommand:(id)aCmd {
NSLog(@"speechRecognizer: %@",(NSString *)aCmd);
}
我对注册的命令尝试了很多次,但我无法在委托中的日志中获取任何消息:(
背景中总是有一些噪音..这可能是它的原因还是我代码中做错了什么?
有人可以建议我一些解决方案吗?
谢谢,
Miraaj
I noticed NSSpeechRecognizer in ADC library and I found it to be very interesting, so to play with it I prepared a simple application which will just listen the command and if recognized it displays it in log.
The code used is:
- (id)init {
if (self = [super init]) {
// Insert code here to initialize your application
NSArray *cmds = [NSArray arrayWithObjects:@"A",@"B", @"C",@"alpha",@"beta",@"vodka",@"wine",nil];
recog = [[NSSpeechRecognizer alloc] init]; // recog is an ivar
[recog setCommands:cmds];
[recog setDelegate:self];
}
return self;
}
- (IBAction)listen:(id)sender
{ NSLog(@"listen:");
if ([sender state] == NSOnState) { // listen
[recog startListening];
} else {
[recog stopListening];
}
}
- (void)speechRecognizer:(NSSpeechRecognizer *)sender didRecognizeCommand:(id)aCmd {
NSLog(@"speechRecognizer: %@",(NSString *)aCmd);
}
I tried it many times for the commands registered but I was unable to get none of the messages in log, in delegate :(
There was always some noise in the background.. could this be the reason for it or I have done something wrong in the code??
Can anyone suggest me some solution for it??
Thanks,
Miraaj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
到目前为止,代码看起来不错。
NSSpeechRecognizer 有时有点棘手,拒绝听正确的单词。你尝试过不同的词语吗?
您是否尝试将 startListening 设置为默认值?
我前段时间写了一个小教程。它是德语的,但也许它会对您有所帮助,或者您可以使用一些翻译工具。
http://cocoa-coding.de/spracherkennung/nsspeechrecognizer1.html
Code looks fine so far.
The NSSpeechRecognizer is a bit tricky sometimes and refuses to listen to the right words. Did you try different words?
Did you try setting startListening as default?
I wrote a little tutorial some time ago. Its in german language but maybe it will help you anyway or you use some translation tool.
http://cocoa-coding.de/spracherkennung/nsspeechrecognizer1.html