private async Task InitialzeSpeechRecognizerForSingleUtterance()
        {
            List <string> initResults = new List <string>();

            try
            {
                AudioContainer.SphinxSpeechRecognizer = new SpeechRecognizer();
                speechRecognizer = AudioContainer.SphinxSpeechRecognizer;

                await Task.Run(() =>
                {
                    var initResult = speechRecognizer.Initialize("\\Assets\\models\\hmm\\en-us", "\\Assets\\models\\dict\\cmu07a.dic");
                    initResults.Add(initResult);
                    initResult = speechRecognizer.AddNgramSearch("goforward", "\\Assets\\models\\lm\\en-us.lm.bin");
                    initResults.Add(initResult);
                });
            }
            catch (Exception ex)
            {
                var initResult = ex.Message;
                initResults.Add(initResult);
            }

            foreach (var result in initResults)
            {
                Debug.WriteLine(result);
            }
        }
Esempio n. 2
0
        private async Task InitialzeSpeechRecognizer()
        {
            List <string> initResults = new List <string>();

            try
            {
                AudioContainer.SphinxSpeechRecognizer = new SpeechRecognizer();
                speechRecognizer = AudioContainer.SphinxSpeechRecognizer;

                speechRecognizer.resultFound += speechRecognizer_resultFound;
                speechRecognizer.resultFinalizedBySilence += speechRecognizer_resultFinalizedBySilence;

                if (!isPhonemeRecognitionEnabled)
                {
                    await Task.Run(() =>
                    {
                        var initResult = speechRecognizer.Initialize("\\Assets\\models\\hmm\\en-us", "\\Assets\\models\\dict\\cmu07a.dic");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddKeyphraseSearch(RecognizerMode.Wakeup.ToString(), WakeupText);
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddGrammarSearch(RecognizerMode.Menu.ToString(), "\\Assets\\models\\grammar\\menu.gram");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddGrammarSearch(RecognizerMode.Digits.ToString(), "\\Assets\\models\\grammar\\digits.gram");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddNgramSearch("forecast", "\\Assets\\models\\lm\\weather.dmp");
                        initResults.Add(initResult);
                    });
                }
                else
                {
                    await Task.Run(() =>
                    {
                        var initResult = speechRecognizer.InitializePhonemeRecognition("\\Assets\\models\\hmm\\en-us");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddPhonesSearch(RecognizerMode.Phones.ToString(), "\\Assets\\models\\lm\\en-us-phone.lm.bin");
                        initResults.Add(initResult);
                    });
                }

                SetRecognizerMode(Mode);
            }
            catch (Exception ex)
            {
                var initResult = ex.Message;
                initResults.Add(initResult);
            }

            foreach (var result in initResults)
            {
                Debug.WriteLine(result);
            }
        }
Esempio n. 3
0
        private void SetupRecognizer(File assetsDir)
        {
            // The recognizer can be configured to perform multiple searches
            // of different kind and switch between them

            Config config = Decoder.DefaultConfig();

            _recognizer = new SpeechRecognizerSetup(config)
                          .SetAcousticModel(new File(assetsDir, "en-us-ptm"))
                          .SetDictionary(new File(assetsDir, "cmudict-en-us.dict"))
                          //.SetRawLogDir(assetsDir) // To disable logging of raw audio comment out this call (takes a lot of space on the device)
                          .GetRecognizer();

            _recognizer.Result         += Recognizer_Result;
            _recognizer.InSpeechChange += Recognizer_InSpeechChange;
            _recognizer.Timeout        += Recognizer_Timeout;
            _recognizer.Stopped        += _recognizer_Stopped;

            /** In your application you might not need to add all those searches.
             * They are added here for demonstration. You can leave just one.
             */

            // Create keyword-activation search.
            _recognizer.AddKeyphraseSearch(KWS_SEARCH, KEYPHRASE);

            // Create grammar-based search for selection between demos
            File menuGrammar = new File(assetsDir, "menu.gram");

            _recognizer.AddGrammarSearch(MENU_SEARCH, menuGrammar);

            // Create grammar-based search for digit recognition
            File digitsGrammar = new File(assetsDir, "digits.gram");

            _recognizer.AddGrammarSearch(DIGITS_SEARCH, digitsGrammar);

            // Create language model search
            File languageModel = new File(assetsDir, "weather.dmp");

            _recognizer.AddNgramSearch(FORECAST_SEARCH, languageModel);

            // Phonetic search

            /*File phoneticModel = new File(assetsDir, "en-phone.dmp");
             * recognizer.Ad(PHONE_SEARCH, phoneticModel);*/

            //switchSearch(KWS_SEARCH);
        }
        private async Task InitialzeSpeechRecognizer()
        {
            List<string> initResults = new List<string>();

            try
            {
                AudioContainer.SphinxSpeechRecognizer = new SpeechRecognizer();
                speechRecognizer = AudioContainer.SphinxSpeechRecognizer;

                speechRecognizer.resultFound += speechRecognizer_resultFound;
                speechRecognizer.resultFinalizedBySilence += speechRecognizer_resultFinalizedBySilence;

                if (!isPhonemeRecognitionEnabled)
                {
                    await Task.Run(() =>
                    {
                        var initResult = speechRecognizer.Initialize("\\Assets\\models\\hmm\\en-us", "\\Assets\\models\\dict\\cmu07a.dic");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddKeyphraseSearch(RecognizerMode.Wakeup.ToString(), WakeupText);
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddGrammarSearch(RecognizerMode.Menu.ToString(), "\\Assets\\models\\grammar\\menu.gram");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddGrammarSearch(RecognizerMode.Digits.ToString(), "\\Assets\\models\\grammar\\digits.gram");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddNgramSearch("forecast", "\\Assets\\models\\lm\\weather.dmp");
                        initResults.Add(initResult);
                    });
                }
                else
                {
                    await Task.Run(() =>
                    {
                        var initResult = speechRecognizer.InitializePhonemeRecognition("\\Assets\\models\\hmm\\en-us");
                        initResults.Add(initResult);
                        initResult = speechRecognizer.AddPhonesSearch(RecognizerMode.Phones.ToString(), "\\Assets\\models\\lm\\en-us-phone.lm.bin");
                        initResults.Add(initResult);
                    });
                }

                SetRecognizerMode(Mode);
            }
            catch (Exception ex)
            {
                var initResult = ex.Message;                
                initResults.Add(initResult);
            }

            foreach (var result in initResults)
            {
                Debug.WriteLine(result);
            }
        }