コード例 #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sensor">Kinect sensor</param>
        /// <param name="grammarElements">Grammar elements</param>
        public SpeechCommandProcessor(KinectSensor sensor, IEnumerable <ISpeechGrammarElement> grammarElements)
        {
            if (sensor == null)
            {
                throw new ArgumentNullException("sensor");
            }
            if (grammarElements == null)
            {
                throw new ArgumentNullException("grammarElements");
            }

            this.ConfidenceThreshold = 0.9f;
            this.sensor          = sensor;
            this.grammarElements = grammarElements;

            IReadOnlyList <AudioBeam> audioBeamList = this.sensor.AudioSource.AudioBeams;

            System.IO.Stream audioStream = audioBeamList[0].OpenInputStream();

            // create the convert stream
            this.kinectAudioStream = new KinectAudioStream(audioStream);

            RecognizerInfo ri = TryGetKinectRecognizer();

            if (null != ri)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                var commandList = new Choices();
                foreach (ISpeechGrammarElement sp in this.grammarElements)
                {
                    foreach (string word in sp.WordList)
                    {
                        commandList.Add(new SemanticResultValue(word, sp.Semantic));
                    }
                }

                var gb = new GrammarBuilder {
                    Culture = ri.Culture
                };
                gb.Append(commandList);

                var g = new Grammar(gb);

                this.speechEngine.LoadGrammar(g);

                this.speechEngine.SpeechRecognized += this.SpeechRecognized;
                this.kinectAudioStream.SpeechActive = true;
                this.speechEngine.SetInputToAudioStream(
                    this.kinectAudioStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                this.speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
        }
コード例 #2
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="sensor">Kinect sensor</param>
        /// <param name="grammarElements">Grammar elements</param>
        public SpeechCommandProcessor(KinectSensor sensor, IEnumerable<ISpeechGrammarElement> grammarElements)
        {
            if (sensor == null)
                throw new ArgumentNullException("sensor");
            if (grammarElements == null)
                throw new ArgumentNullException("grammarElements");

            this.ConfidenceThreshold = 0.9f;
            this.sensor = sensor;
            this.grammarElements = grammarElements;

            IReadOnlyList<AudioBeam> audioBeamList = this.sensor.AudioSource.AudioBeams;
            System.IO.Stream audioStream = audioBeamList[0].OpenInputStream();

            // create the convert stream
            this.kinectAudioStream = new KinectAudioStream(audioStream);

            RecognizerInfo ri = TryGetKinectRecognizer();

            if (null != ri)
            {
                this.speechEngine = new SpeechRecognitionEngine(ri.Id);

                var commandList = new Choices();
                foreach (ISpeechGrammarElement sp in this.grammarElements)
                {
                    foreach (string word in sp.WordList)
                    {
                        commandList.Add(new SemanticResultValue(word, sp.Semantic));
                    }
                }

                var gb = new GrammarBuilder { Culture = ri.Culture };
                gb.Append(commandList);

                var g = new Grammar(gb);

                this.speechEngine.LoadGrammar(g);

                this.speechEngine.SpeechRecognized += this.SpeechRecognized;
                this.kinectAudioStream.SpeechActive = true;
                this.speechEngine.SetInputToAudioStream(
                this.kinectAudioStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
                this.speechEngine.RecognizeAsync(RecognizeMode.Multiple);
            }
        }