コード例 #1
0
        public async Task MultipleListeners()
        {
            var clientConfig = CreateClientWithCredentials(CreateConfigDefault(), TestsReferences.DefaultASRURL, TestsReferences.User, TestsReferences.Password);
            var lModelLst    = new LanguageModelList();

            lModelLst.AddFromUri(TestsReferences.FreeLanguageModel);
            var audioSource = new FileAudioSource(TestsReferences.AudioPizzaVeg, AudioType.DETECT);

            using (SpeechRecognizer speechRecognizer = SpeechRecognizer.Create(clientConfig))
            {
                lModelLst.AddFromUri(TestsReferences.GramPizzaHttp);

                Events = new EventsPassed();
                speechRecognizer.OnListening += SpeechRecognizer_OnListening;
                speechRecognizer.OnPartialRecognitionResult += SpeechRecognizer_OnPartialRecognitionResult;
                speechRecognizer.OnRecognitionResult        += SpeechRecognizer_OnRecognitionResult;
                speechRecognizer.OnSpeechStart += SpeechRecognizer_OnSpeechStart;
                speechRecognizer.OnSpeechStop  += SpeechRecognizer_OnSpeechStop;

                speechRecognizer.Recognize(audioSource, lModelLst);

                Task <bool> checkEventsPassed = CheckIfEventsHasPassed();

                bool result = await checkEventsPassed;

                Assert.IsTrue(result);
            }
            Events = null;
        }
コード例 #2
0
        public async Task MultipleListeners()
        {
            var clientConfig = this.CreateClientConfigDefault(this.CreateConfigDefault());
            var audioSource  = new FileAudioSource(@"8k\pizza\pizza_veg_audio_8k.wav");

            Events = new EventsPassed();
            SpeechRecognizer speechRecognizer = SpeechRecognizer.Create(clientConfig);

            try
            {
                //Cria modelo de linguagem com gramática para o áudio de pizza:
                var lModelLst = new LanguageModelList();
                lModelLst.AddFromUri("http://vmh102.cpqd.com.br:8280/asr_dist/repository/grammars/dynamic-gram/pizza.gram");

                speechRecognizer.OnListening += SpeechRecognizer_OnListening;
                speechRecognizer.OnPartialRecognitionResult += SpeechRecognizer_OnPartialRecognitionResult;
                speechRecognizer.OnRecognitionResult        += SpeechRecognizer_OnRecognitionResult;
                speechRecognizer.OnSpeechStart += SpeechRecognizer_OnSpeechStart;
                speechRecognizer.OnSpeechStop  += SpeechRecognizer_OnSpeechStop;

                speechRecognizer.Recognize(audioSource, lModelLst);

                Task <bool> checkEventsPassed = this.CheckIfEventsHasPassed();

                bool result = await checkEventsPassed;

                Assert.IsTrue(result);
            }
            catch (Exception ex)
            {
                Events = null;
                throw ex;
            }
            finally
            {
                speechRecognizer.Close();
            }

            Events = null;
        }