Exemple #1
0
        MicrophoneRecognitionClient CreateMicrophoneRecoClientWithIntent(string recoLanguage)
        {
            WriteLine("--- Start microphone dictation with Intent detection ----");

            MicrophoneRecognitionClientWithIntent intentMicClient =
                SpeechRecognitionServiceFactory.CreateMicrophoneClientWithIntent(recoLanguage,
                                                                                 _speechAPIAccountKey,
                                                                                 _luisAppID,
                                                                                 _luisAPIAccountKey);

            if (recoLanguage == "zh-CN")
            {
                intentMicClient =
                    SpeechRecognitionServiceFactory.CreateMicrophoneClientWithIntent(recoLanguage,
                                                                                     _speechAPIAccountKey,
                                                                                     _luisAppIDChinese,
                                                                                     _luisAPIAccountKey);
            }
            intentMicClient.OnIntent += OnIntentHandler;

            // Event handlers for speech recognition results
            intentMicClient.OnMicrophoneStatus        += OnMicrophoneStatus;
            intentMicClient.OnPartialResponseReceived += OnPartialResponseReceivedHandler;
            intentMicClient.OnResponseReceived        += OnMicShortPhraseResponseReceivedHandler;
            intentMicClient.OnConversationError       += OnConversationErrorHandler;

            intentMicClient.StartMicAndRecognition();

            return(intentMicClient);
        }
 public SpeechToTextTools()
 {
     MicClient = SpeechRecognitionServiceFactory.CreateMicrophoneClientWithIntent("fr-FR", SubscriptionKey, )
 }
        private void initMicClient(string locale, string luisApp)
        {
            _micSubscriptions.Clear();

            _micClient = SpeechRecognitionServiceFactory.CreateMicrophoneClientWithIntent(locale, BingSpeechAppKey, luisApp, LuisAppKey);

            var sub1 = Observable.FromEventPattern(record, "Checked")
                       .Subscribe(_ =>
            {
                responseText.Text = "Recording!";
                Debug.WriteLine("Start speech");
                _micClient.StartMicAndRecognition();
            });
            var sub2 = Observable.FromEventPattern(record, "Unchecked")
                       .Subscribe(_ =>
            {
                responseText.Text += "\nStopped recording";
                Debug.WriteLine("Stop speech");
                _micClient.EndMicAndRecognition();
            });

            var sub3 = Observable.FromEventPattern <SpeechIntentEventArgs>(_micClient, "OnIntent")
                       .Select(e => e.EventArgs as SpeechIntentEventArgs)
                       .ObserveOnDispatcher()
                       .SelectMany(args =>
            {
                using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(args.Payload)))
                {
                    var serializer     = new DataContractJsonSerializer(typeof(ResponsePayload));
                    var payload        = serializer.ReadObject(ms) as ResponsePayload;
                    responseText.Text += "\nDetected speech: " + payload.query;
                    if (payload.intents.Length > 0)
                    {
                        responseText.Text += "\nIntent: " + payload.intents[0].intent + " (" + payload.intents[0].score + ")";
                        bool isLight       = payload.entities.FirstOrDefault(e => e.type == "light") != null;
                        responseText.Text += "\nEntity: " + (isLight ? "light" : "unknown");
                        if (isLight)
                        {
                            responseText.Text += "\nSending command... ";
                            return(SendIntentAsync(_iotClient, payload.intents[0].intent, "light", parseFrequency(payload)).ToObservable());
                        }
                        else
                        {
                            responseText.Text += "\nNO ENTITIES FOUND. No action required. ";
                            return(Task.Delay(TimeSpan.FromMilliseconds(0)).ToObservable());
                        }
                    }
                    else
                    {
                        responseText.Text += "\nNO INTENTS FOUND. No action required. ";
                        return(Task.Delay(TimeSpan.FromMilliseconds(0)).ToObservable());
                    }
                }
            })
                       .ObserveOnDispatcher()
                       .Subscribe(_ =>
            {
                responseText.Text += "Done";
            });

            _micSubscriptions.Add(sub1);
            _micSubscriptions.Add(sub2);
            _micSubscriptions.Add(sub3);
        }