Exemple #1
0
        private static void WriteResponseResult(SpeechResponseEventArgs e)
        {
            if (e.PhraseResponse.Results.Length == 0)
            {
                Console.WriteLine("No phrase response is available.");
                result.tableName = "INVALID";
                result.rowID     = -1;
                micClient.EndMicAndRecognition();
            }
            else
            {
                Console.WriteLine("********* Final n-BEST Results *********");
                for (int i = 0; i < e.PhraseResponse.Results.Length; i++)
                {
                    Console.WriteLine(
                        "[{0}] Confidence={1}, Text=\"{2}\"",
                        i,
                        e.PhraseResponse.Results[i].Confidence,
                        e.PhraseResponse.Results[i].DisplayText);
                }
                string        prefix = string.Empty, resultTable = "INVALID";
                int           resultRowRecord = -1;
                List <string> response        = new List <string>();
                foreach (var item in e.PhraseResponse.Results)
                {
                    response.Add(item.DisplayText);
                }
                resultTable      = GetDirectMatchingPrefix(response);
                result.tableName = resultTable;
                for (int i = 0; i < e.PhraseResponse.Results.Length; i++)
                {
                    if (!resultTable.Equals("INVALID", StringComparison.InvariantCultureIgnoreCase))
                    {
                        break;
                    }
                    string sentence = Regex.Replace(e.PhraseResponse.Results[i].DisplayText, "[^a-zA-Z0-9_ ]+", "");
                    if (sentence.Contains(" "))
                    {
                        prefix = sentence.Substring(0, sentence.IndexOf(" "));
                    }
                    else
                    {
                        prefix = sentence;
                    }

                    resultTable      = GetMatchingPrefix(prefix);
                    result.tableName = resultTable;
                }
                resultRowRecord = GetDirectMatchingRowRecord(response, result.tableName);
                result.rowID    = resultRowRecord;
                for (int i = 0; i < e.PhraseResponse.Results.Length; i++)
                {
                    if (resultRowRecord != -1)
                    {
                        break;
                    }
                    string sentence = Regex.Replace(e.PhraseResponse.Results[i].DisplayText, "[^a-zA-Z0-9_  ]+", "");
                    if (sentence.Length > 0)
                    {
                        int j = sentence.IndexOf(" ") + 1;
                        sentence        = sentence.Substring(j);
                        resultRowRecord = GetMatchingRow(result.tableName, sentence);
                        result.rowID    = resultRowRecord;
                    }
                }
            }
            CommandExecution cmdExec = new CommandExecution();

            if (result == null || result.tableName == "INVALID" || result.rowID == -1)
            {
                TextToSpeech.Speak("Sorry! I did not get you.");
            }
            else if (result.tableName == "BROWSE")
            {
                cmdExec.Run(result.rowID);
                TextToSpeech.Speak("Your website is launched");
            }
            else if (result.tableName == "CLIPBOARD")
            {
                cmdExec.CopyToClipBoard(result.rowID);
                TextToSpeech.Speak("Copied your text to clipboard");
            }
            else if (result.tableName == "ARENA")
            {
                Batch b = new Batch();
                using (var db = new Models())
                {
                    var text = db.ArenaDB.Where(q => q.ArenaID == result.rowID).FirstOrDefault();
                    if (!string.IsNullOrEmpty(text.TextCommand))
                    {
                        b.findexe(text.TextCommand);
                    }
                }
            }
            else if (result.tableName == "JIRA")
            {
                cmdExec.ExecuteResult(result.rowID);
            }
            else if (result.tableName == "OUTLOOK")
            {
                new OutlookUtils().HandleOutlookOperations(result.rowID);
            }
        }