Jos*_*one 7 .net c# wpf speech-recognition speech-to-text
我刚开始在C#.Net中尝试使用Windows Speech to Text功能.我目前已经掌握了基础知识(IE - 说些什么,它会根据你说的提供输出).但是,我正在努力弄清楚如何实际接收用户输入作为变量.
我的意思是,例如.如果用户说:
"Call me John"
Run Code Online (Sandbox Code Playgroud)
然后我希望能够把这个词John作为变量,然后存储,例如,人员用户名.
我目前的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;
}
}
Run Code Online (Sandbox Code Playgroud)
NB:writeConsolas只是一个美化的追加线RichTextBox.
我想添加另一个case执行以下操作的内容:
case "call me"
username = e.Result.GetWordFollowingCallMe() //Obv not a method, but thats the general idea.
break;
Run Code Online (Sandbox Code Playgroud)
显然,没有这样的方法,但这是我希望实现的一般想法.有没有办法搜索特定的短语(IE :) Call me并采取以下单词?
编辑:我应该注意,e.Result.Text只返回它可以匹配字典中的文本的单词.
在您的情况下,它看起来并不代表e.Result.Text您可以枚举的内容:您正在检查开始文本的单词,而不是整个文本。在这种情况下,您不应该使用 a switch,而应该使用if-链then:else
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
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1134 次 |
| 最近记录: |