好的,所以我正在为我的AI重新设计当前的基础结构,然后将其创建为一个阵列。但是我不确定如何获取数组“ dictonary”中的第11个值
这是代码!
string name = "Jarvis";
string[] dictionary = new string[] { "hello", "how", "are", "you", "sup", "wake", "up", "daddys", "home", "what", "version", "whats", "your" };
bool helloflag = false;
void recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
string code = "";
//ResultText = "Hello how are you"
string[] words = e.Result.Text.Split(' ');
//words = ["Hello", "how", "are", "you"]
foreach (string word in words)
{
for (int index = 0; index < dictionary.Count(); index++)
{
if (word == dictionary[index])
{
code += index.ToString();
}
}
}
//code = "123"; //how are you
//code = "236"; //are you up
//HELLO
if ((code == "0") || (code == "4"))
{
Jarvis.Speak("Hello sir");
helloflag = true;
} else if ((helloflag == true ) && (code == "123"))
{
Jarvis.Speak("im good sir");
helloflag = false;
}
这是.NET语音API的一部分,但是使用数组来调用您说的单词。
添加到时code
,需要在代码之间放置一个分隔符。否则,您将无法判断12
单词1是紧随其后的单词2,还是单词12。例如
code += index.toString() + " ";
然后,您可以执行以下操作:
if (code == "10 9 2 3 ") // whats version are you
不要忘记最后的空格。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句