NSSpeechRecognizer 示例

发布于 2024-11-09 03:30:07 字数 68 浏览 3 评论 0原文

好吧,我需要这样做:

等待命令“晚安”。然后运行一个动作。

有人可以解释如何实现这一点吗?

Ok so I need to do this:

Wait for command, "Goodnight". Then run an action.

Can someone explain how do accomplish this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

青朷 2024-11-16 03:30:07

试试这个网站:

http://www.cocoadev.com/index.pl?NSSpeechRecognizer

并修改如下:

NSSpeechRecognizer *listen;
NSArray *cmds = [NSArray arrayWithObjects:@"goodnight",nil];
listen = [[NSSpeechRecognizer alloc] init];
[listen setCommands:cmds];
[listen setDelegate:self];
[listen setListensInForegroundOnly:NO];
[listen startListening];
[listen setBlocksOtherRecognizers:YES];

- (void)speechRecognizer:(NSSpeechRecognizer *)sender didRecognizeCommand:(id)aCmd {
    if ([(NSString *)aCmd isEqualToString:@"goodnight"]) {
        [self performSelector:@selector(goodnightMethod:)];
    }
}

您处理晚安的方法是(根据我所写的):

-(void)goodnightMethod:(id)sender {
    //Do stuff here...
}

Try this website:

http://www.cocoadev.com/index.pl?NSSpeechRecognizer

And modify as such:

NSSpeechRecognizer *listen;
NSArray *cmds = [NSArray arrayWithObjects:@"goodnight",nil];
listen = [[NSSpeechRecognizer alloc] init];
[listen setCommands:cmds];
[listen setDelegate:self];
[listen setListensInForegroundOnly:NO];
[listen startListening];
[listen setBlocksOtherRecognizers:YES];

- (void)speechRecognizer:(NSSpeechRecognizer *)sender didRecognizeCommand:(id)aCmd {
    if ([(NSString *)aCmd isEqualToString:@"goodnight"]) {
        [self performSelector:@selector(goodnightMethod:)];
    }
}

Your method for handling good night would be (with accordance to what I have written):

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