Ejemplo n.º 1
0
 Grammar ConvertToGrammar(NuiGrammar nuiGrammar)
 {
     if (nuiGrammar.GrammarType == NuiGrammar.NuiGrammarType.Basic)
     {
         var choices = new Choices();
         foreach (var item in nuiGrammar.Items)
         {
             choices.Add(item.Text);
         }
         var builder = new GrammarBuilder();
         builder.Culture = speechRecognitionEngine.RecognizerInfo.Culture;
         builder.Append(choices);
         var grammar = new Grammar(builder);
         return(grammar);
     }
     throw new NotSupportedException(
               "Anything other than Basic grammar type is not supported.");
 }
Ejemplo n.º 2
0
        public void AddGrammar(NuiGrammar newGrammar)
        {
            if (this.grammar != null)
            {
                this.grammar = newGrammar;
                var g = ConvertToGrammar(grammar);
                speechRecognitionEngine.UnloadAllGrammars();
                speechRecognitionEngine.LoadGrammar(g);
            }
            else
            {

                this.grammar = newGrammar;

                if ((speechRecognitionEngine != null) && (speechRecognitionEngine.Grammars.Count == 1))
                {
                    throw new NotSupportedException("Only 1 grammar is supported in this release.");
                }

                var recognizer = SpeechRecognitionEngine.InstalledRecognizers()
                    .Where(x => x.Id == KinectSpeechRecognizer).FirstOrDefault();

                if (recognizer == null)
                {
                    throw new InvalidOperationException("No speech recognizer found.");
                }

                speechRecognitionEngine = new SpeechRecognitionEngine(recognizer);

                var g = ConvertToGrammar(grammar);
                speechRecognitionEngine.LoadGrammar(g);
                speechRecognitionEngine.SpeechDetected += new EventHandler<SpeechDetectedEventArgs>(speechRecognitionEngine_SpeechDetected);
                speechRecognitionEngine.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(speechRecognitionEngine_SpeechRecognitionRejected);
                speechRecognitionEngine.SpeechRecognized += new EventHandler<Microsoft.Speech.Recognition.SpeechRecognizedEventArgs>(speechRecognitionEngine_SpeechRecognized);
                this.speechThread = new Thread(InitializeSpeech);
                this.speechThread.Start();
            }
        }
Ejemplo n.º 3
0
        public void AddGrammar(NuiGrammar newGrammar)
        {
            if (this.grammar != null)
            {
                this.grammar = newGrammar;
                var g = ConvertToGrammar(grammar);
                speechRecognitionEngine.UnloadAllGrammars();
                speechRecognitionEngine.LoadGrammar(g);
            }
            else
            {
                this.grammar = newGrammar;

                if ((speechRecognitionEngine != null) && (speechRecognitionEngine.Grammars.Count == 1))
                {
                    throw new NotSupportedException("Only 1 grammar is supported in this release.");
                }

                var recognizer = SpeechRecognitionEngine.InstalledRecognizers()
                                 .Where(x => x.Id == KinectSpeechRecognizer).FirstOrDefault();

                if (recognizer == null)
                {
                    throw new InvalidOperationException("No speech recognizer found.");
                }

                speechRecognitionEngine = new SpeechRecognitionEngine(recognizer);

                var g = ConvertToGrammar(grammar);
                speechRecognitionEngine.LoadGrammar(g);
                speechRecognitionEngine.SpeechDetected            += new EventHandler <SpeechDetectedEventArgs>(speechRecognitionEngine_SpeechDetected);
                speechRecognitionEngine.SpeechRecognitionRejected += new EventHandler <SpeechRecognitionRejectedEventArgs>(speechRecognitionEngine_SpeechRecognitionRejected);
                speechRecognitionEngine.SpeechRecognized          += new EventHandler <Microsoft.Speech.Recognition.SpeechRecognizedEventArgs>(speechRecognitionEngine_SpeechRecognized);
                this.speechThread = new Thread(InitializeSpeech);
                this.speechThread.Start();
            }
        }
Ejemplo n.º 4
0
 Grammar ConvertToGrammar(NuiGrammar nuiGrammar)
 {
     if (nuiGrammar.GrammarType == NuiGrammar.NuiGrammarType.Basic)
     {
         var choices = new Choices();
         foreach (var item in nuiGrammar.Items)
         {
             choices.Add(item.Text);
         }
         var builder = new GrammarBuilder();
         builder.Culture = speechRecognitionEngine.RecognizerInfo.Culture;
         builder.Append(choices);
         var grammar = new Grammar(builder);
         return grammar;
     }
     throw new NotSupportedException(
         "Anything other than Basic grammar type is not supported.");
 }
 public void AddGrammar(NuiGrammar grammar)
 {
 }
Ejemplo n.º 6
0
 public void AddGrammar(NuiGrammar grammar)
 {
 }