当前位置: 首页>>代码示例>>C#>>正文


C# GrammarBuilder.AppendWildcard方法代码示例

本文整理汇总了C#中GrammarBuilder.AppendWildcard方法的典型用法代码示例。如果您正苦于以下问题:C# GrammarBuilder.AppendWildcard方法的具体用法?C# GrammarBuilder.AppendWildcard怎么用?C# GrammarBuilder.AppendWildcard使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GrammarBuilder的用法示例。


在下文中一共展示了GrammarBuilder.AppendWildcard方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetGrammar_Custom

        public GrammarBuilder GetGrammar_Custom(string grammar)
        {
            Choices globalChoices = new Choices();
            string[] sentences = grammar.Split('|');
            foreach (string s in sentences)
            {
                GrammarBuilder sentenceBuilder = new GrammarBuilder();
                string[] words = s.Split(' ');
                foreach (string w in words)
                {
                    if (m_vocabulories.ContainsKey(w))
                        sentenceBuilder.Append(new Choices(m_vocabulories[w].ToArray()));
                    else if (w == "#Dictation")
                        sentenceBuilder.AppendDictation();
                    else if (w == "#WildCard")
                        sentenceBuilder.AppendWildcard();
                    else if (w != "")
                        sentenceBuilder.Append(w);
                }
                globalChoices.Add(sentenceBuilder);
            }

            GrammarBuilder globalBuilder = new GrammarBuilder(globalChoices);
            globalBuilder.Culture = m_culture;
            Console.WriteLine(globalBuilder.DebugShowPhrases);
            return globalBuilder;
        }
开发者ID:xufango,项目名称:contrib_bk,代码行数:27,代码来源:RobotGrammarManager.cs

示例2: LoadGrammar

        private void LoadGrammar(SpeechRecognitionEngine speechRecognitionEngine)
        {
            // Build a simple grammar of shapes, colors, and some simple program control
            var single = new Choices();
            foreach (var phrase in SinglePhrases)
                single.Add(phrase.Key);

            var gameplay = new Choices();
            foreach (var phrase in GameplayPhrases)
                gameplay.Add(phrase.Key);

            var shapes = new Choices();
            foreach (var phrase in ShapePhrases)
                shapes.Add(phrase.Key);

            var colors = new Choices();
            foreach (var phrase in ColorPhrases)
                colors.Add(phrase.Key);

            var coloredShapeGrammar = new GrammarBuilder();
            coloredShapeGrammar.Append(colors);
            coloredShapeGrammar.Append(shapes);

            var objectChoices = new Choices();
            objectChoices.Add(gameplay);
            objectChoices.Add(shapes);
            objectChoices.Add(colors);
            objectChoices.Add(coloredShapeGrammar);

            var actionGrammar = new GrammarBuilder();
            actionGrammar.AppendWildcard();
            actionGrammar.Append(objectChoices);

            var allChoices = new Choices();
            allChoices.Add(actionGrammar);
            allChoices.Add(single);

            var gb = new GrammarBuilder();
            gb.Culture = speechRecognitionEngine.RecognizerInfo.Culture; //This is needed to ensure that it will work on machines with any culture, not just en-us.
            gb.Append(allChoices);

            var g = new Grammar(gb);
            speechRecognitionEngine.LoadGrammar(g);
            speechRecognitionEngine.SpeechRecognized += sre_SpeechRecognized;
            speechRecognitionEngine.SpeechHypothesized += sre_SpeechHypothesized;
            speechRecognitionEngine.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);
        }
开发者ID:thoschmidt,项目名称:shoopdoup,代码行数:47,代码来源:SpeechRecognizer.cs

示例3: Recognizer

        public Recognizer()
        {
            RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();
            if (ri == null)
                return;

            sre = new SpeechRecognitionEngine(ri.Id);

            // Build a simple grammar of shapes, colors, and some simple program control
            var single = new Choices();
            foreach (var phrase in SinglePhrases)
                single.Add(phrase.Key);

            var gameplay = new Choices();
            foreach (var phrase in GameplayPhrases)
                gameplay.Add(phrase.Key);

            var shapes = new Choices();
            foreach (var phrase in ShapePhrases)
                shapes.Add(phrase.Key);

            var colors = new Choices();
            foreach (var phrase in ColorPhrases)
                colors.Add(phrase.Key);

            var coloredShapeGrammar = new GrammarBuilder();
            coloredShapeGrammar.Append(colors);
            coloredShapeGrammar.Append(shapes);

            var objectChoices = new Choices();
            objectChoices.Add(gameplay);
            objectChoices.Add(shapes);
            objectChoices.Add(colors);
            objectChoices.Add(coloredShapeGrammar);

            var actionGrammar = new GrammarBuilder();
            actionGrammar.AppendWildcard();
            actionGrammar.Append(objectChoices);

            var allChoices = new Choices();
            allChoices.Add(actionGrammar);
            allChoices.Add(single);

            var gb = new GrammarBuilder();
            gb.Append(allChoices);

            var g = new Grammar(gb);
            sre.LoadGrammar(g);
            sre.SpeechRecognized += sre_SpeechRecognized;
            sre.SpeechHypothesized += sre_SpeechHypothesized;
            sre.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);

            var t = new Thread(StartDMO);
            t.Start();

            valid = true;
        }
开发者ID:adr2370,项目名称:Pokemon-Kinect-Game,代码行数:57,代码来源:Recognizer.cs

示例4: LoadGrammar

        private void LoadGrammar(SpeechRecognitionEngine speechRecognitionEngine)
        {
            // Build a simple grammar of shapes, colors, and some simple program control
            var robot = new Choices();
            foreach (var phrase in this.robotPhrases)
            {
                robot.Add(phrase.Key);
            }

            var single = new Choices();
            foreach (var phrase in this.singlePhrases)
            {
                single.Add(phrase.Key);
            }

            var gameplay = new Choices();
            foreach (var phrase in this.gameplayPhrases)
            {
                gameplay.Add(phrase.Key);
            }

            var shapes = new Choices();
            foreach (var phrase in this.shapePhrases)
            {
                shapes.Add(phrase.Key);
            }

            var colors = new Choices();
            foreach (var phrase in this.colorPhrases)
            {
                colors.Add(phrase.Key);
            }

            var coloredShapeGrammar = new GrammarBuilder();
            coloredShapeGrammar.Append(colors);
            coloredShapeGrammar.Append(shapes);

            var objectChoices = new Choices();
            objectChoices.Add(robot);
            //objectChoices.Add(gameplay);
            //objectChoices.Add(shapes);
            //objectChoices.Add(colors);
            //objectChoices.Add(coloredShapeGrammar);

            var actionGrammar = new GrammarBuilder();
            actionGrammar.AppendWildcard();
            actionGrammar.Append(objectChoices);

            var allChoices = new Choices();
            allChoices.Add(actionGrammar);
            //allChoices.Add(single);

            // This is needed to ensure that it will work on machines with any culture, not just en-us.
            var gb = new GrammarBuilder { Culture = speechRecognitionEngine.RecognizerInfo.Culture };
            gb.Append(allChoices);

            var g = new Grammar(gb);
            speechRecognitionEngine.LoadGrammar(g);
            speechRecognitionEngine.SpeechRecognized += this.SreSpeechRecognized;
            speechRecognitionEngine.SpeechHypothesized += this.SreSpeechHypothesized;
            speechRecognitionEngine.SpeechRecognitionRejected += this.SreSpeechRecognitionRejected;
        }
开发者ID:nerndt,项目名称:iRobotKinect,代码行数:62,代码来源:SpeechRecognizer.cs

示例5: CreateGrammars

        ///////////////////////////////////////////////////////////////////
        private void CreateGrammars(RecognizerInfo rInfo)
        {
            //定义操作类型
            var controls = new Choices();
            controls.Add("打开");
            controls.Add("关闭");
            controls.Add("调高");
            controls.Add("降低");

            //定义所操作的设备
            var devices = new Choices();
            devices.Add("电视");
            devices.Add("红色电灯");
            devices.Add("绿色电灯");
            devices.Add("空调");

            //定义操作参数
            var param = new Choices();
            param.Add("亮度");
            param.Add("温度");
            param.Add("频道");
            param.Add("电源");

            var gBulider = new GrammarBuilder();
            gBulider.Culture = rInfo.Culture;
            gBulider.Append(controls);
            gBulider.Append(devices);
            gBulider.Append(param);
            gBulider.AppendWildcard();

            var g = new Grammar(gBulider);
            _speechRecognitionEngine.LoadGrammar(g);

            var q = new GrammarBuilder { Culture = rInfo.Culture };
            q.Append("退出 程序");
            var quit = new Grammar(q);

            _speechRecognitionEngine.LoadGrammar(quit);
        }
开发者ID:cnyangyijai,项目名称:Kinect,代码行数:40,代码来源:MainWindow.xaml.cs

示例6: Vocal

        public Vocal(GameStateManagementGame myGame)
        {
            thisGameIsAwesome = myGame;
            RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r => r.Id == RecognizerId).FirstOrDefault();
            if (ri == null)
                return;

            sre = new SpeechRecognitionEngine(ri.Id);

            var single = new Choices();
            foreach (var phrase in SinglePhrases)
                single.Add(phrase.Key);

            var gameplay = new Choices();
            foreach (var phrase in GameplayPhrases)
                gameplay.Add(phrase.Key);

            //            var colors = new Choices();
            //            foreach (var phrase in ColorPhrases)
            //                colors.Add(phrase.Key);

            var numbers = new Choices();
            foreach (var phrase in NumberPhrases)
                numbers.Add(phrase.Key);

            var numberAction = new GrammarBuilder();
            numberAction.Append(gameplay);
            numberAction.Append(numbers);

            var doubleNumber = new GrammarBuilder();
            numberAction.Append(gameplay);
            numberAction.Append(numbers);
            numberAction.Append(numbers);

            var objectChoices = new Choices();
            objectChoices.Add(gameplay);
            //            objectChoices.Add(colors);
            objectChoices.Add(numbers);
            objectChoices.Add(doubleNumber);

            var actionGrammar = new GrammarBuilder();
            actionGrammar.AppendWildcard();
            actionGrammar.Append(objectChoices);

            var allChoices = new Choices();
            allChoices.Add(actionGrammar);
            allChoices.Add(single);

            var gb = new GrammarBuilder();
            gb.Append(allChoices);

            var g = new Grammar(gb);
            sre.LoadGrammar(g);
            sre.SpeechRecognized += sre_SpeechRecognized;
            sre.SpeechHypothesized += sre_SpeechHypothesized;
            sre.SpeechRecognitionRejected += new EventHandler<SpeechRecognitionRejectedEventArgs>(sre_SpeechRecognitionRejected);

            var t = new Thread(StartDMO);
            t.Name = "Kinect Audio";
            t.Start();

            valid = true;
        }
开发者ID:ProjPossibility,项目名称:USC-AccessibleKinect,代码行数:63,代码来源:Vocal.cs

示例7: CreateLightCommandGrammar

        private static GrammarBuilder CreateLightCommandGrammar(LightActionSpec lightActionSpec)
        {
            var allLightsIdentifierChoices = GrammarHelper.ConvertIdentyListToGrammarBuilder(lightActionSpec.LightIdentifiers.ToList());
            var lightActions = lightActionSpec.GetAllActions();
            var lightsLables = lightActionSpec.GetLightSubjectChoices();

            var actionGrammarBuilders = new List<GrammarBuilder>();
            foreach(var action in lightActions)
            {
                var actionChoices = action.ToChoices();

                var actionGrammer1 = new GrammarBuilder();
                actionGrammer1.AppendWildcard();
                actionGrammer1.Append(new SemanticResultKey(LightActionSemanticKey, actionChoices));
                actionGrammer1.AppendWildcard();
                actionGrammer1.Append(new SemanticResultKey(LightIdentifierSemanticKey, allLightsIdentifierChoices));
                actionGrammer1.AppendWildcard();
                actionGrammer1.Append(new SemanticResultKey(CommandSubjectSemanticKey, lightsLables));

                var actionGrammar2 = new GrammarBuilder();
                actionGrammar2.AppendWildcard();
                actionGrammar2.Append(new SemanticResultKey(LightActionSemanticKey, actionChoices));
                actionGrammar2.AppendWildcard();
                actionGrammar2.Append(new SemanticResultKey(CommandSubjectSemanticKey, lightsLables));
                actionGrammar2.AppendWildcard();
                actionGrammar2.Append(new SemanticResultKey(LightIdentifierSemanticKey, allLightsIdentifierChoices));

                actionGrammarBuilders.Add(actionGrammer1);
                actionGrammarBuilders.Add(actionGrammar2);
            }

            return new GrammarBuilder(new Choices(actionGrammarBuilders.ToArray()));
        }
开发者ID:patrickchisel,项目名称:HomeSpeechInterface,代码行数:33,代码来源:HouseVoiceCommandHandler.cs

示例8: Main

        static void Main(string[] args)
        {
            //initialize synthesizer
            speech = new SpeechSynthesizer();

            //setup the speech engine to listen to our microphone
            engine = new SpeechRecognitionEngine();
            engine.SetInputToDefaultAudioDevice();

            WriteLine("I'm listening...");

            WriteLine("Say 'Hello Computer'");
            //this listens for a specific phrase - in this case
            //'hello computer'
            var phraseGrammar = new GrammarBuilder("Hello Computer");
            ListenForResult(phraseGrammar);

            WriteLine("What is your favorite Red, Blue, or Green color?");
            //GrammarBuilder used to construct phrases for the engine to detect
            var simpleChoiceGrammar = new GrammarBuilder();
            //create an array of words the user could say
            var choices = new Choices("red", "green", "blue");
            simpleChoiceGrammar.Append(choices);
            ListenForResult(simpleChoiceGrammar);

            WriteLine("What is your favorite Red, Blue, or Green color?");
            var mappedChoiceGrammar = new GrammarBuilder("color");
            var choices2 = new Choices();
            //add each word individually as a choice, with a corresponding value
            //we can test for
            choices2.Add(new SemanticResultValue("red", 1));
            choices2.Add(new SemanticResultValue("green", 2));
            choices2.Add(new SemanticResultValue("blue", 3));
            //associate the value of this choice with a "key" we can look for
            mappedChoiceGrammar.Append(new SemanticResultKey("color", choices2));

            //because we appended to the original grammar builder of "color",
            //the user has to say "color red" in order for this to work
            var mappedChoiceResult = ListenForResult(mappedChoiceGrammar);

            //test if result contains our semantic key
            if (mappedChoiceResult.Semantics.ContainsKey("color"))
            {
                //get value from SemanticResultValue
                var color = (int)mappedChoiceResult.Semantics["color"].Value;
                var colorText = "";
                switch (color)
                {
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Red;
                        colorText = "Red";
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Green;
                        colorText = "Green";
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        colorText = "Blue";
                        break;
                }
                WriteLine(colorText + " is my favorite too!");
            }

            WriteLine("What is your name?");
            var wildcardGrammar = new GrammarBuilder("My name is");
            var wildcard = new GrammarBuilder();
            //append a "wildcard", which is a placeholder for a phrase that
            //we do not decode
            wildcard.AppendWildcard();
            wildcardGrammar.Append(new SemanticResultKey("name", wildcard));
            var wildcardResult = ListenForResult(wildcardGrammar);

            if (wildcardResult.Semantics.ContainsKey("name"))
            {
                //note that wildcard will not actually return anything
                //for a value... it's only a placeholder
                var name = (string)wildcardResult.Semantics["name"].Value;
                WriteLine("Hi " + name + "!");
            }

            WriteLine("What is your name?");
            var dictationGrammar = new GrammarBuilder("My name is");
            var dictation = new GrammarBuilder();
            //append a "dictation", which is a placeholder for a phrase
            //that the speech engine attempts to decode to a string
            dictation.AppendDictation();
            dictationGrammar.Append(new SemanticResultKey("name", dictation));
            var dictationResult = ListenForResult(dictationGrammar);

            if(dictationResult.Semantics.ContainsKey("name"))
            {
                //this will have the best guess at what the user said
                //usually with hilarious results
                var name = (string)dictationResult.Semantics["name"].Value;
                WriteLine("Hi " + name + "!");
            }

            WriteLine("Done listening");

//.........这里部分代码省略.........
开发者ID:ChadMcCallum,项目名称:SpeechRecognition.NET,代码行数:101,代码来源:Program.cs

示例9: MainWindow


//.........这里部分代码省略.........

            // set the status text
            this.StatusText = this.kinectSensor.IsAvailable ? Properties.Resources.RunningStatusText
                                                            : Properties.Resources.NoSensorStatusText;

            RecognizerInfo ri = TryGetKinectRecognizer();

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

                //var directions = new Choices();
                //directions.Add(new SemanticResultValue("hide", "hide"));
                //directions.Add(new SemanticResultValue("minimize", "minimize"));
                //directions.Add(new SemanticResultValue("maximize", "maximize"));
                //directions.Add(new SemanticResultValue("snap left", "snap left"));
                //directions.Add(new SemanticResultValue("snap right", "snap right"));
                //directions.Add(new SemanticResultValue("front", "front"));
                //directions.Add(new SemanticResultValue("drag", "drag"));
                //directions.Add(new SemanticResultValue("get windows", "get windows"));

                // Grammar for snapping
                GrammarBuilder snap = new GrammarBuilder { Culture = ri.Culture };
                // Any window
                snap.Append(new Choices("snap"));
                snap.Append(new Choices("Spotify", "Genie", "Chrome", "Media Player", "Visual Studio", "Github", "Eclipse", "Word", "Notepad"));
                snap.Append(new Choices("left", "right", "down", "up"));
                var g = new Grammar(snap);
                this.speechEngine.LoadGrammar(g);


                GrammarBuilder snap2 = new GrammarBuilder { Culture = ri.Culture };
                snap2.Append(new Choices("snap"));
                snap2.AppendWildcard();
                snap2.Append(new Choices("left", "right", "down", "up"));
                var g4 = new Grammar(snap2);
                this.speechEngine.LoadGrammar(g4);


                GrammarBuilder grab1 = new GrammarBuilder { Culture = ri.Culture };
                grab1.Append(new Choices("grab"));
                grab1.Append(new Choices("Spotify", "Genie", "Chrome", "Media Player", "Visual Studio", "Github", "Eclipse", "Word", "Notepad"));
                var g1 = new Grammar(grab1);
                this.speechEngine.LoadGrammar(g1);


                GrammarBuilder drag1 = new GrammarBuilder { Culture = ri.Culture };
                drag1.Append(new Choices("grab"));
                drag1.Append(new Choices("Spotify", "Genie", "Chrome", "Media Player", "Visual Studio", "Github", "Eclipse", "Word", "Notepad"));
                var d1 = new Grammar(drag1);
                this.speechEngine.LoadGrammar(d1);

                GrammarBuilder grab2 = new GrammarBuilder { Culture = ri.Culture };
                // Any window
                grab2.Append(new Choices("grab"));
                var g2 = new Grammar(grab2);
                this.speechEngine.LoadGrammar(g2);

                GrammarBuilder dropit = new GrammarBuilder { Culture = ri.Culture };
                // Any window
                dropit.Append(new Choices("drop it"));
                var drop = new Grammar(dropit);
                this.speechEngine.LoadGrammar(drop);

                GrammarBuilder mouse = new GrammarBuilder { Culture = ri.Culture };
                // Any window
开发者ID:TomWerner,项目名称:HandsOnInterface,代码行数:67,代码来源:MainWindow.xaml.cs

示例10: CreateSubGrammarWithWildcard

 private GrammarBuilder CreateSubGrammarWithWildcard(string vocabulary)
 {
     if (vocabulary.Contains("*"))
     {
         string[] subchoicesWildcard = vocabulary.Split('*');
         GrammarBuilder grammarBuilder = new GrammarBuilder();
         for (int i = 0; i < subchoicesWildcard.Length; i++)
         {
             grammarBuilder.Append(CreateSubGrammarWithDigits(subchoicesWildcard[i]));
             if (i < subchoicesWildcard.Length - 1)
                 grammarBuilder.AppendWildcard();
         }
         return grammarBuilder;
     }
     else
         return new Choices(CreateSubGrammarWithDigits(vocabulary));
 }
开发者ID:VincentGuigui,项目名称:IKinea,代码行数:17,代码来源:MeasureViewModel.cs

示例11: getBaseGrammarBuilder

        /// \brief builds the base grammar
        /// 
        /// \returns the base grammar for this plugin
        private GrammarBuilder getBaseGrammarBuilder(String methodName)
        {
            GrammarBuilder builder = new GrammarBuilder { Culture = Engine.RecognizerInfo.Culture };

            builder.Append(new Choices(startCommands));
            builder.AppendWildcard();

            foreach (string word in methodName.Split('_'))
            {
                builder.Append(new Choices(word));
                builder.AppendWildcard();
            }

            return builder;
        }
开发者ID:KayoticSully,项目名称:SpeakEasy,代码行数:18,代码来源:PluginBase.cs

示例12: ToGrammarBuilder

        public GrammarBuilder ToGrammarBuilder()
        {
            GrammarBuilder builder = new GrammarBuilder();

            Queue<PhoneticChoice> foundChoices;
            String[] tokens = ToTokens(out foundChoices);

            foreach (String token in tokens)
            {
                switch (token)
                {
                    case CHOICE:
                        PhoneticChoice choice = foundChoices.Dequeue();
                        builder.Append(new Choices(choice.PossibleValues));
                        break;
                    case WILD_CARD:
                        builder.AppendWildcard();
                        break;
                    case DICTATION:
                        builder.AppendDictation();
                        break;
                    default:
                        //Regular Text is just appended
                        builder.Append(token);
                        break;
                }
            }

            return builder;
        }
开发者ID:jumonb,项目名称:mastercontrol,代码行数:30,代码来源:Phonetic.cs

示例13: CreateGrammar

        /// <summary>
        /// returns a grammar with choices. The choices are passed in the string by enclosing them in parenthesis
        /// ie: Please fly to {Boston, Florida, New York} on {Saturday, Sunday}
        /// </summary>
        /// <returns></returns>
        public static Grammar CreateGrammar(string text)
        {
            var builder = new GrammarBuilder();
            Choices choices = new Choices();
            var finalBuilder = new GrammarBuilder();
            var finalChoices = new Choices();
            Grammar returnGrammar;

            string data = text.Trim();
            char delim = ' ';
            string[] words = data.Split(delim); // holds the data already split by words
            bool insideList = false;
            string phrase = "";

            foreach (var word in words)
            {
                if (word.StartsWith("{"))
                {
                    if (phrase.Length > 0)
                    {
                        phrase = phrase.Trim();
                        builder.Append(phrase);
                        phrase = "";
                    }
                    choices = new Choices();
                    insideList = true;
                    if (word.EndsWith(","))
                    {
                        choices.Add(word.TrimNonLetters());
                    }
                    else
                        phrase += word.TrimNonLetters() + " ";

                }
                else if (word.EndsWith("}"))
                {
                    word.TrimNonLetters();
                    if (phrase.Length > 0)
                    {
                        phrase += word;
                        choices.Add(phrase);
                        phrase = "";
                    }
                    else
                        choices.Add(word);
                    builder.Append(choices);
                    insideList = false;
                }
                else if (word.EndsWith(","))
                {
                    if (insideList)
                    {
                        phrase += word.TrimNonLetters();
                        choices.Add(phrase);
                        phrase = "";
                    }
                    else
                        phrase += word + " ";
                }
            }

            if (phrase.Length > 0)
                builder.Append(phrase.Trim());

            finalChoices.Add(builder);

            var beforeBuilder = new GrammarBuilder();
            beforeBuilder.AppendWildcard();
            var beforeKey = new SemanticResultKey("beforeKey", beforeBuilder);

            var afterBuilder = new GrammarBuilder();
            afterBuilder.AppendWildcard();
            var afterKey = new SemanticResultKey("afterKey", afterBuilder);

            finalBuilder.Append(beforeBuilder);
            finalBuilder.Append(finalChoices);
            finalBuilder.Append(afterBuilder);

            returnGrammar = new Grammar(finalBuilder);

            return returnGrammar;
        }
开发者ID:juancito0316,项目名称:JuansLibrary,代码行数:87,代码来源:SpeechHelper.cs

示例14: OnOpenSensor


//.........这里部分代码省略.........
            if (_sensor != null)
            {
                _sensor.Open();

                _reader = _sensor.OpenMultiSourceFrameReader(FrameSourceTypes.Color | FrameSourceTypes.Depth | FrameSourceTypes.Infrared | FrameSourceTypes.Body);
                _reader.MultiSourceFrameArrived += Reader_MultiSourceFrameArrived;
            }
            
            
            // FOR THE SOUND
            this.sensor = KinectSensor.GetDefault();

            // open the sensor
            this.sensor.Open();

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

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

            RecognizerInfo ri = TryGetKinectRecognizer();


            // these are engine where we put what to analyse in speech recogniition it can not be done if we can use bing speech recognizer but it is not possible to use now in germany as in beta phase

            this.speechEngine = new SpeechRecognitionEngine(ri.Id);  // speech recognition engine

            var directions = new Choices();                                  // direction is the vaariable used to direct where we have to go
            directions.Add(new SemanticResultValue("ZoomIn", "ZOOMIN"));    // first one is the text which system see in audio and if match then it save the second name in it which we can access to run what we want
            directions.Add(new SemanticResultValue("ZoomIn", "ZOOMIN"));
            directions.Add(new SemanticResultValue("In", "ZOOMIN"));
            directions.Add(new SemanticResultValue("ZoomOut", "ZOOMOUT"));
            directions.Add(new SemanticResultValue("Out", "ZOOMOUT"));
            directions.Add(new SemanticResultValue("ZoomOut", "ZOOMOUT"));
            directions.Add(new SemanticResultValue("Left", "LEFT"));
            directions.Add(new SemanticResultValue("Right", "RIGHT"));
            directions.Add(new SemanticResultValue("Up", "UP"));
            directions.Add(new SemanticResultValue("Down", "DOWN"));

            // places
            directions.Add(new SemanticResultValue("Go India", "INDIA"));
            directions.Add(new SemanticResultValue("india", "INDIA"));
            directions.Add(new SemanticResultValue("Go AMERICA", "AMERICA"));
            directions.Add(new SemanticResultValue("america", "AMERICA"));
            directions.Add(new SemanticResultValue("Go SanDiego", "SANDIEGO"));
            directions.Add(new SemanticResultValue("SanDiego", "SANDIEGO"));
            directions.Add(new SemanticResultValue("MY PLACE", "MYPLACE"));              // this will not work through window app as cant activate gps through eo web browser 
            directions.Add(new SemanticResultValue("San Francisco Bay", "SANFRANCISCO"));
            directions.Add(new SemanticResultValue("Mount Everest", "MOUNTEVEREST"));
            directions.Add(new SemanticResultValue("Grand Canyon", "GRANDCANYON"));
            directions.Add(new SemanticResultValue("hannover", "HANOVER"));
            directions.Add(new SemanticResultValue("newyork", "NEWYORK"));
            directions.Add(new SemanticResultValue("Delhi", "DELHI"));
            directions.Add(new SemanticResultValue("Goa", "GOA"));
            directions.Add(new SemanticResultValue("Mumbai", "MUMBAI"));
            directions.Add(new SemanticResultValue("Banglore", "BANGLORE"));
            directions.Add(new SemanticResultValue("Europe", "EUROPE"));
            directions.Add(new SemanticResultValue("Germany", "GERMANY"));
            directions.Add(new SemanticResultValue("Switzerland", "SWITZERLAND"));
            directions.Add(new SemanticResultValue("Amsterdam", "AMSTERDAM"));
            directions.Add(new SemanticResultValue("Belgium", "BELGIUM"));
            directions.Add(new SemanticResultValue("Hildesheim", "HILDESHEIM"));
            directions.Add(new SemanticResultValue("Hamburg", "HAMBURG"));
            directions.Add(new SemanticResultValue("Berlin", "BERLIN"));
            directions.Add(new SemanticResultValue("Prague", "PRAGUE"));
            directions.Add(new SemanticResultValue("Sylt", "SYLT"));
            directions.Add(new SemanticResultValue("Paris", "PARIS"));
            directions.Add(new SemanticResultValue("Great Pyramid", "GREAT"));
            directions.Add(new SemanticResultValue("Effiel Tower", "Tower"));
            directions.Add(new SemanticResultValue("Taj Mahal", "TAj"));
            directions.Add(new SemanticResultValue("Pisa", "PISA"));
            directions.Add(new SemanticResultValue("Venice", "VENICE"));
            //tools
            directions.Add(new SemanticResultValue("Fly", "FLY"));
            directions.Add(new SemanticResultValue("walk", "WALK"));
            directions.Add(new SemanticResultValue("valk", "WALK"));
            directions.Add(new SemanticResultValue("Back", "BACK"));
            directions.Add(new SemanticResultValue("photo", "PHOTO"));
            directions.Add(new SemanticResultValue("PHOTO", "PHOTO"));
            var gb = new GrammarBuilder { Culture = ri.Culture }; // to run recognizer
            gb.Append(directions);
            gb.AppendWildcard();  // this is used so that second word of saying wil not be count to detect the acccuracy of word

            var grr = new Grammar(gb);

            this.speechEngine.LoadGrammar(grr); // to load the grammer

            this.speechEngine.SpeechRecognized += this.SpeechRecognized;              // called if speech recognized
            this.speechEngine.SpeechRecognitionRejected += this.SpeechRejected;       // called if speech rejected

            // let the convertStream know speech is going active
            this.convertStream.SpeechActive = true;

            this.speechEngine.SetInputToAudioStream(
            this.convertStream, new SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, null));
            this.speechEngine.RecognizeAsync(RecognizeMode.Multiple);
      
        }
开发者ID:ayushaggar,项目名称:Kinect-V2-Map-Visualisation,代码行数:101,代码来源:MainWindow.xaml.cs

示例15: CreateGrammars

        /*
         * create voice grammar
         */
        private void CreateGrammars(RecognizerInfo ri)
        {
            var create = new Choices();
            create.Add("move");
            create.Add("go");

            var direction = new Choices();
            direction.Add("front");
            direction.Add("left");
            direction.Add("right");
            direction.Add("back");
            direction.Add("up");
            direction.Add("down");

            //var shapes = new Choices();
            //shapes.Add("circle");
            //shapes.Add("triangle");
            //shapes.Add("square");
            //shapes.Add("diamond");

            var gb = new GrammarBuilder();
            gb.Culture = ri.Culture;
            gb.Append(create);
            gb.AppendWildcard();
            gb.Append(direction);
            //gb.Append(shapes);
            gb.Append("roger that");

            var g = new Grammar(gb);
            _sre.LoadGrammar(g);

            var q = new GrammarBuilder { Culture = ri.Culture };
            q.Append("quit application");
            var quit = new Grammar(q);

            _sre.LoadGrammar(quit);
        }
开发者ID:antonyjzp,项目名称:VoiceDrone,代码行数:40,代码来源:MainWindow.xaml.cs


注:本文中的GrammarBuilder.AppendWildcard方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。