简单的 NSSpeechRecognizer 代码,不起作用!

发布于 2024-08-21 11:46:34 字数 977 浏览 7 评论 0原文

我注意到 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

匿名的好友 2024-08-28 11:46:34

到目前为止,代码看起来不错。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文