获取用户输入的语音? [英] Get user input from Speech?

查看:150
本文介绍了获取用户输入的语音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始尝试Windows的语音到文本的C#.NET功能。我现在有工作的基本知识(IE浏览器 - 说一下,它会根据你说的话提供输出)。不过,我在努力弄清楚如何真正免费获赠用户输入的变量。

I have just started trying out the Windows Speech to Text capabilities in C# .Net. I currently have the basics working (IE - Say something, and it will provide output based on what you say). However, I am struggling to figure out how to actually recieve user input as a variable.

我的意思这一点,就是为例。如果用户说:

What I mean by this, is that for example. If the user says:

"Call me John"

然后,我希望能够继续走字约翰·作为一个变量,然后保存,作为说,人员的用户名。

Then I want to be able to take the word John as a variable and then store that as say, the persons username.

我现在的 SpeechRecognized 事件如下:

void zeusSpeechRecognised(object sender, SpeechRecognizedEventArgs e)
    {
        writeConsolas(e.Result.Text, username);
        switch (e.Result.Grammar.RuleName)
        {
            case "settingsRules":
                switch (e.Result.Text)
                {
                    case "test":
                        writeConsolas("What do you want me to test?", me);
                        break;
                    case "change username":
                        writeConsolas("What do you want to be called?", me);
                        break;
                    case "exit":
                        writeConsolas("Do you wish me to exit?", me);
                        break;
                }
                break;
        }
    }

注: writeConsolas 只是一个华而不实的附加行到的RichTextBox

NB:writeConsolas is just a glorified append line to a RichTextBox.

我想补充的另一个情况其中执行以下操作:

I would like to add another case which does the following:

case "call me"
    username = e.Result.GetWordFollowingCallMe() //Obv not a method, but thats the general idea.
    break;

显然,有没有这样的方法,但是这是我希望实现的总体思路。有没有一种方法来搜索特定词组(IE:给我打电话),并采取以下字

编辑:我要指出,该e.Result.Text只返回的话,它可以匹配在字典文本

I should note, that the e.Result.Text only returns words that it can match to Text in the dictionary.

推荐答案

它看起来并不像你的情况 e.Result.Text 重presents的东西,您可以枚举:您所检查的开始文本,而不是在它的整个案文的话。在这样的情况下,你不应该使用开关,如果去连锁 - 然后 - 其他!而非:

It does not look like in your situation e.Result.Text represents something that you can enumerate: you are checking the words that start the text, not the text in its entirety. In cases like this, you should not use a switch, and go for a chain of if-then-elses instead:

var text = e.Result.Text;
if (text.StartsWith("test")) {
    writeConsolas("What do you want me to test?", me);
} else if (text.StartsWith("change username")) {
    writeConsolas("What do you want to be called?", me);
} else if (text.StartsWith("exit")) {
    writeConsolas("Do you wish me to exit?", me);
} else if (text.StartsWith("call me")) {
    // Here you have the whole text. Chop off the "call me" part,
    // using Substring(), and do whatever you need to do with the rest of it
} else 
    ...

这篇关于获取用户输入的语音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆