Ejemplo n.º 1
0
 public Grammar getGrammar()
 {
     Choices setChoices = new Choices("I'd like to set an alarm for", "Set alarm for", "Set Alarm Clock", "Set Alarm");
     GrammarBuilder morningChoices = new Choices("am", "in the morning");
     morningChoices.Append(new SemanticResultValue(true));
     GrammarBuilder eveningChoices = new Choices("pm", "tonight", "at night");
     eveningChoices.Append(new SemanticResultValue(false));
     Choices amOrPm = new Choices(morningChoices, eveningChoices);
     SemanticResultKey amOrPmKey = new SemanticResultKey("AmPm", amOrPm);
     Choices hours = new Choices("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12");
     Choices minutes = new Choices("10", "15", "20", "25", "30", "35", "40", "45", "50", "55", "60", "o'clock", " ");
     GrammarBuilder thisGB = new GrammarBuilder();
     thisGB.Append(setChoices);
     thisGB.Append(new SemanticResultKey("Hours", hours));
     thisGB.Append(new SemanticResultKey("Minutes", minutes));
     thisGB.Append(amOrPmKey);
     Grammar thisGrammar = new Grammar(thisGB);
     // Set the Grammar name
     thisGrammar.Name = _grammarName;
     return thisGrammar;
 }
Ejemplo n.º 2
0
        private void InitializeSpeechRecognition()
        {
            RecognizerInfo ri = GetKinectRecognizer();

            if (ri == null)
            {
                MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
                return;
            }

            try
            {
                speechRecognizer = new SpeechRecognitionEngine(ri.Id);
            }
            catch
            {
                MessageBox.Show(
                    @"There was a problem initializing Speech Recognition.
Ensure you have the Microsoft Speech SDK installed and configured.",
                    "Failed to load Speech SDK",
                    MessageBoxButton.OK,
                    MessageBoxImage.Error);
            }

            var firstword = new Choices();

            foreach (string value in firstWord.Keys)
            {
                firstword.Add(value);
            }

            GrammarBuilder firstword1 = new Choices(new string[] { "seir" });

            firstword1.Append("surita");
            firstword1.Append("fimm");
            firstword1.Append("groenn");
            firstword1.Append("vindr");

            GrammarBuilder firstword2 = new Choices(new string[] { "oss" });

            firstword2.Append("naeo");
            firstword2.Append("fyor");
            firstword2.Append("regin");
            firstword2.Append("tinada");
            firstword2.Append("varindo");
            firstword2.Append("yotsun");

            GrammarBuilder exit = new Choices(new string[] { "nox" });

            exit.Append("eterna");

            Choices first = new Choices();

            first.Add(new Choices(new GrammarBuilder[] { firstword1, firstword2, exit }));

            var gb = new GrammarBuilder();

            gb.Culture = ri.Culture;
            gb.Append(first);

            var g = new Grammar(gb);

            speechRecognizer.LoadGrammar(g);
            speechRecognizer.SpeechRecognized          += speechRecognizer_SpeechRecognized;
            speechRecognizer.SpeechHypothesized        += speechRecognizer_SpeechHypothesized;
            speechRecognizer.SpeechRecognitionRejected += speechRecognizer_SpeechRecognitionRejected;

            if (Kinect == null || speechRecognizer == null)
            {
                return;
            }

            var audioSource = this.Kinect.AudioSource;

            audioSource.BeamAngleMode = BeamAngleMode.Adaptive;
            var kinectStream = audioSource.Start();

            speechRecognizer.SetInputToAudioStream(
                kinectStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
            speechRecognizer.RecognizeAsync(RecognizeMode.Multiple);
        }
        private void InitGrammar()
        {
            GrammarBuilder readGrammar = new Choices(new string[] { "read article" });
            Choices articleChoice = new Choices();
            for (int i = 1; i <= 30; i++)
            {
                articleChoice.Add(i.ToString());
            }
            readGrammar.Append(articleChoice);

            GrammarBuilder saveGrammar = new Choices(new string[] { "save article" });
            saveGrammar.Append(articleChoice);

            GrammarBuilder otherGrammar = new Choices(new string[] { "receive hacker news", "stop", "test" });

            //GrammarBuilder commands = new Choices(new string[] { "receive hacker news", "stop", "test" });
            Choices commands = new Choices();
            commands.Add(new Choices(new GrammarBuilder[] { readGrammar, saveGrammar, otherGrammar }));

            var grammar = new Grammar(commands);
            this._speechRecognizer.LoadGrammar(grammar);
        }