// Handle the SpeechRecognized event.
        //WARNING: this could be asynchronous to everything else
        void Recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string text = e.Result.Text;

            string debug = "";

            foreach (RecognizedWordUnit w in e.Result.Words)
            {
                debug += w.Text + "(" + w.Confidence + ") ";
            }
            bool  anyLowConfidence = false;
            float minConfidence    = .91f;

            if (text.IndexOf("Sallie say") == 0)
            {
                minConfidence = .6f;
            }
            foreach (RecognizedWordUnit word in e.Result.Words)
            {
                if (word.Confidence < minConfidence)
                {
                    anyLowConfidence = true;
                }
            }
            if (e.Result.Confidence < .9 || e.Result.Words[0].Confidence < .92 || anyLowConfidence)
            {
                //System.Media.SystemSounds.Asterisk.Play();
                Debug.WriteLine("Words Detected: " + debug + " IGNORED");
                return;
            }
            Debug.WriteLine("Words Detected: " + debug);

            //use this to work with pronunciations instead of words
            //foreach (RecognizedWordUnit word in e.Result.Words)
            //{
            //    words.Add(word.Pronunciation);
            //}
            //return;

            string[] tempWords = text.Split(' ');
            foreach (string word in tempWords)
            {
                if (word.ToLower() != "sallie" && word.ToLower() != "computer")
                {
                    words.Add(word.ToLower());
                }
            }
            ModuleHearWords nmHear = (ModuleHearWords)FindModuleByType(typeof(ModuleHearWords));

            if (nmHear != null)
            {
                String phrase = e.Result.Text;
                if (e.Result.Words.Count != 1)
                {
                    int i = phrase.IndexOf(' ');
                    phrase = phrase.Substring(i + 1);
                }
                nmHear.HearPhrase(phrase);
            }
        }
Exemple #2
0
        private void SimulatePhrase(string Phrase)
        {
            ModuleHearWords nmWords = (ModuleHearWords)FindModuleByType(typeof(ModuleHearWords));

            if (nmWords != null)
            {
                nmWords.HearPhrase(Phrase);
            }
        }
Exemple #3
0
        // Handle the SpeechRecognized event.
        //WARNING: this could be asynchronous to everything else
        void Recognizer_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
        {
            string text = e.Result.Text;

            //get the audio to do something

/*            RecognizedAudio ra = e.Result.GetAudioForWordRange(e.Result.Words[0], e.Result.Words[e.Result.Words.Count-1]);
 *          System.IO.MemoryStream stream = new System.IO.MemoryStream();
 *          ra.WriteToAudioStream(stream);
 *          stream.Position = 0;
 *          byte[] rawBytes = new byte[stream.Length];
 *          stream.Read(rawBytes, 0, (int)stream.Length);
 *          System.IO.FileStream fStream = new System.IO.FileStream(@"C:\Users\c_sim\Documents\BrainSim\xx.wav",System.IO.FileMode.CreateNew);
 *          ra.WriteToAudioStream(fStream);
 *          fStream.Close();
 */

            string debug = "";

            foreach (RecognizedWordUnit w in e.Result.Words)
            {
                debug += w.Text + "(" + w.Confidence + ") ";
            }
            bool  anyLowConfidence = false;
            float minConfidence    = .91f;

            if (text.IndexOf("Sallie say") == 0)
            {
                minConfidence = .6f;
            }
            foreach (RecognizedWordUnit word in e.Result.Words)
            {
                if (word.Confidence < minConfidence)
                {
                    anyLowConfidence = true;
                }
            }
            //if (e.Result.Confidence < .9 || e.Result.Words[0].Confidence < .92 || anyLowConfidence)
            //{
            //    //System.Media.SystemSounds.Asterisk.Play();
            //    Debug.WriteLine("Words Detected: " + debug + " IGNORED");
            //    return;
            //}
            Debug.WriteLine("Words Detected: " + debug);

            //use this to work with pronunciations instead of words
            //foreach (RecognizedWordUnit word in e.Result.Words)
            //{
            //    words.Add(word.Pronunciation);
            //}
            //return;

            string[] tempWords = text.Split(' ');
            foreach (string word in tempWords)
            {
                if (word.ToLower() != "sallie" && word.ToLower() != "computer")
                {
                    words.Add(word.ToLower());
                }
            }
            ModuleHearWords nmHear = (ModuleHearWords)FindModuleByType(typeof(ModuleHearWords));

            if (nmHear != null)
            {
                String phrase = e.Result.Text;
                if (e.Result.Words.Count != 1)
                {
                    int i = phrase.IndexOf(' ');
                    phrase = phrase.Substring(i + 1);
                }
                nmHear.HearPhrase(phrase);
            }
        }