Esempio n. 1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                SpeechFactory speechFactory = SpeechFactory.FromSubscription(luisKey, "");
                recognizer = speechFactory.CreateIntentRecognizer("zh-cn");

                // 创建意图识别器用到的模型
                var model = LanguageUnderstandingModel.FromSubscription(luisKey, luisAppId, luisRegion);

                // 将模型中的意图加入到意图识别器中
                recognizer.AddIntent("None", model, "None");
                recognizer.AddIntent("TurnOn", model, "TurnOn");
                recognizer.AddIntent("TurnOff", model, "TurnOff");

                // 挂载识别中的事件
                // 收到中间结果
                recognizer.IntermediateResultReceived += Recognizer_IntermediateResultReceived;
                // 收到最终结果
                recognizer.FinalResultReceived += Recognizer_FinalResultReceived;
                // 发生错误
                recognizer.RecognitionErrorRaised += Recognizer_RecognitionErrorRaised;

                // 启动语音识别器,开始持续监听音频输入
                recognizer.StartContinuousRecognitionAsync();
            }
            catch (Exception ex)
            {
                Log(ex.Message);
            }
        }
        // Intent recognition using microphone.
        public static async Task RecognitionWithMicrophoneAsync()
        {
            // <intentRecognitionWithMicrophone>
            // Creates an instance of a speech config with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Services Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            // The default language is "en-us".
            var config = SpeechConfig.FromSubscription("YourLanguageUnderstandingSubscriptionKey", "YourLanguageUnderstandingServiceRegion");

            // Creates an intent recognizer using microphone as audio input.
            using (var recognizer = new IntentRecognizer(config))
            {
                // Creates a Language Understanding model using the app id, and adds specific intents from your model
                var model = LanguageUnderstandingModel.FromAppId("YourLanguageUnderstandingAppId");
                recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName1", "id1");
                recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName2", "id2");
                recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName3", "any-IntentId-here");

                // Starts recognizing.
                Console.WriteLine("Say something...");

                // Performs recognition. RecognizeOnceAsync() returns when the first utterance has been recognized,
                // so it is suitable only for single shot recognition like command or query. For long-running
                // recognition, use StartContinuousRecognitionAsync() instead.
                var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                // Checks result.
                if (result.Reason == ResultReason.RecognizedIntent)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent Id: {result.IntentId}.");
                    Console.WriteLine($"    Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
                }
                else if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent not recognized.");
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                }
            }
            // </intentRecognitionWithMicrophone>
        }
Esempio n. 3
0
        public async Task StartAsync(string fileName = null)
        {
            var speechConfig = SpeechConfig.FromSubscription(this.settings.SubscriptionKey, this.settings.Region);

            speechConfig.SpeechRecognitionLanguage = "de-de";
            speechConfig.OutputFormat = OutputFormat.Detailed;

            using (var audioInput = fileName == null ? AudioConfig.FromDefaultMicrophoneInput() : AudioConfig.FromWavFileInput(fileName))
            {
                using (var intentRecognizer = new IntentRecognizer(speechConfig, audioInput))
                {
                    stopRecognition = new TaskCompletionSource <int>();

                    var model = LanguageUnderstandingModel.FromAppId(this.settings.LuisAppId);

                    intentRecognizer.AddAllIntents(model);

                    intentRecognizer.SessionStarted      += IntentRecognizer_SessionStarted;
                    intentRecognizer.Recognized          += IntentRecognizer_Recognized;
                    intentRecognizer.Recognizing         += IntentRecognizer_Recognizing;
                    intentRecognizer.SessionStopped      += IntentRecognizer_SessionStopped;
                    intentRecognizer.SpeechEndDetected   += IntentRecognizer_SpeechEndDetected;
                    intentRecognizer.SpeechStartDetected += IntentRecognizer_SpeechStartDetected;
                    intentRecognizer.Canceled            += IntentRecognizer_Canceled;

                    await intentRecognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                    Task.WaitAny(stopRecognition.Task);

                    await intentRecognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
                }
            }
        }
Esempio n. 4
0
        private async Task <LuisResult> RecognizeSpeechWithIntentRecognizerAsync(string speechFile)
        {
            var speechConfig = SpeechConfig.FromEndpoint(this.LuisConfiguration.SpeechEndpoint, this.LuisConfiguration.EndpointKey);

            using (var audioInput = AudioConfig.FromWavFileInput(speechFile))
                using (var recognizer = new IntentRecognizer(speechConfig, audioInput))
                {
                    // Add intents to intent recognizer
                    var model = LanguageUnderstandingModel.FromAppId(this.LuisConfiguration.AppId);
                    recognizer.AddIntent(model, "None", "None");
                    var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                    // Checks result.
                    // For some reason RecognizeOnceAsync always return ResultReason.RecognizedSpeech
                    // when intent is recognized. It's because we don't add all possible intents (note that this IS intentional)
                    // in code via AddIntent method.
                    if (result.Reason == ResultReason.RecognizedSpeech || result.Reason == ResultReason.RecognizedIntent)
                    {
                        var content = result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);
                        return(JsonConvert.DeserializeObject <LuisResult>(content));
                    }
                    else if (result.Reason == ResultReason.NoMatch)
                    {
                        Logger.LogWarning("Received 'NoMatch' result from Cognitive Services.");
                        return(null);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Failed to get speech recognition result. Reason = '{result.Reason}'");
                    }
                }
        }
        public async Task RecognizeSpeech()
        {
            var audioConfig  = AudioConfig.FromDefaultMicrophoneInput();
            var speechConfig = SpeechConfig.FromSubscription(key, "westus2");

            // Creates a speech recognizer.
            using (var recognizer = new IntentRecognizer(speechConfig, audioConfig))
            {
                // Hide user secrets later
                var model = LanguageUnderstandingModel.FromAppId(Environment.GetEnvironmentVariable("LUIS_APP_ID"));
                recognizer.AddAllIntents(model);

                var stopRecognition = new TaskCompletionSource <int>();
                // Can add logic to exit using voice command, "Thanks see you at the window" etc.
                // Subscribe to appropriate events
                recognizer.Recognizing += (s, e) =>
                {
                    // Use this to send partial responses
                    Console.WriteLine($"Partial: {e.Result.Text}");
                };

                recognizer.Recognized += (s, e) =>
                {
                    var exit = ProcessRecognizedText(s, e);
                    if (exit)
                    {
                        recognizer.StopContinuousRecognitionAsync().Wait(); //ConfigureAwait(false);
                    }
                };

                recognizer.SessionStarted += (s, e) =>
                {
                    Console.WriteLine("Session started event.");
                };

                recognizer.SessionStopped += (s, e) =>
                {
                    Console.WriteLine("Session stopped event.");
                    stopRecognition.TrySetResult(0);
                };

                recognizer.Canceled += (s, e) =>
                {
                    Console.WriteLine(e.ErrorDetails);
                    stopRecognition.TrySetResult(0);
                };

                // Instantiate new Order object
                _order = new Order();

                Console.WriteLine("Say something to get started, or \"Exit\" to quit.");
                await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                // Need more understanding about this part
                Task.WaitAny(new[] { stopRecognition.Task });
            }
        }
        // Intent recognition in the specified language, using microphone.
        public static async Task RecognitionWithMicrophoneUsingLanguageAsync()
        {
            // <intentRecognitionWithLanguage>
            // Creates an instance of a speech factory with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Service Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            var factory = SpeechFactory.FromSubscription("YourLanguageUnderstandingSubscriptionKey", "YourLanguageUnderstandingServiceRegion");

            // Creates an intent recognizer in the specified language using microphone as audio input.
            var lang = "de-de";

            using (var recognizer = factory.CreateIntentRecognizer(lang))
            {
                // Creates a Language Understanding model using the app id, and adds specific intents from your model
                var model = LanguageUnderstandingModel.FromAppId("YourLanguageUnderstandingAppId");
                recognizer.AddIntent("id1", model, "YourLanguageUnderstandingIntentName1");
                recognizer.AddIntent("id2", model, "YourLanguageUnderstandingIntentName2");
                recognizer.AddIntent("any-IntentId-here", model, "YourLanguageUnderstandingIntentName3");

                // Starts recognizing.
                Console.WriteLine("Say something in " + lang + "...");

                // Performs recognition.
                // RecognizeAsync() returns when the first utterance has been recognized, so it is suitable
                // only for single shot recognition like command or query. For long-running recognition, use
                // StartContinuousRecognitionAsync() instead.
                var result = await recognizer.RecognizeAsync().ConfigureAwait(false);

                // Checks result.
                if (result.RecognitionStatus != RecognitionStatus.Recognized)
                {
                    Console.WriteLine($"Recognition status: {result.RecognitionStatus.ToString()}");
                    if (result.RecognitionStatus == RecognitionStatus.Canceled)
                    {
                        Console.WriteLine($"There was an error, reason: {result.RecognitionFailureReason}");
                    }
                    else
                    {
                        Console.WriteLine("No speech could be recognized.\n");
                    }
                }
                else
                {
                    Console.WriteLine($"We recognized: {result.Text}.");
                    Console.WriteLine($"\n    Intent Id: {result.IntentId}.");
                    Console.WriteLine($"\n    Language Understanding JSON: {result.Properties.Get<string>(ResultPropertyKind.LanguageUnderstandingJson)}.");
                }
            }
            // </intentRecognitionWithLanguage>
        }
Esempio n. 7
0
        public IntentRegonisor()
        {
            var config = SpeechConfig.FromSubscription(
                Secret.LuisPredictionKey, Secret.Region);

            var model = LanguageUnderstandingModel.FromAppId(Secret.LuisAppId);

            recognizer = new IntentRecognizer(config);

            recognizer.AddAllIntents(model);
        }
    /// <summary>
    /// Creates and initializes the IntentRecognizer
    /// </summary>
    void CreateIntentRecognizer()
    {
        if (LUISAppKey.Length == 0 || LUISAppKey == "YourLUISAppKey")
        {
            recognizedString = "You forgot to obtain Cognitive Services LUIS credentials and inserting them in this app." + Environment.NewLine +
                               "See the README file and/or the instructions in the Awake() function for more info before proceeding.";
            errorString = "ERROR: Missing service credentials";
            UnityEngine.Debug.LogFormat(errorString);
            return;
        }
        UnityEngine.Debug.LogFormat("Creating Intent Recognizer.");
        recognizedString = "Initializing intent recognition, please wait...";

        if (intentreco == null)
        {
            // Creates an instance of a speech config with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Services Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            // The default language is "en-us".
            var config = SpeechConfig.FromSubscription(LUISAppKey, LUISRegion);
            // Creates an intent recognizer using microphone as audio input.
            intentreco = new IntentRecognizer(config);

            // Creates a Language Understanding model using the app id, and adds specific intents from your model
            var model = LanguageUnderstandingModel.FromAppId(LUISAppId);
            intentreco.AddIntent(model, "ChangeColor", "color");
            intentreco.AddIntent(model, "Transform", "transform");
            intentreco.AddIntent(model, "Help", "help");
            intentreco.AddIntent(model, "None", "none");

            // Subscribes to speech events.
            intentreco.Recognizing         += RecognizingHandler;
            intentreco.Recognized          += RecognizedHandler;
            intentreco.SpeechStartDetected += SpeechStartDetectedHandler;
            intentreco.SpeechEndDetected   += SpeechEndDetectedHandler;
            intentreco.Canceled            += CanceledHandler;
            intentreco.SessionStarted      += SessionStartedHandler;
            intentreco.SessionStopped      += SessionStoppedHandler;
        }
        UnityEngine.Debug.LogFormat("CreateIntentRecognizer exit");
    }
Esempio n. 9
0
        async static Task Main(string[] args)
        {
            const string WAKE_WORD    = "hey computer";
            var          speechConfig = SpeechConfig.FromSubscription("e073d2855d604ddda74ba6518ab2e6b3", "westeurope");
            var          Intentconfig = SpeechConfig.FromSubscription("9051c66d5ba949ac84e32b01c37eb9b4", "westus");
            var          audioConfig  = AudioConfig.FromDefaultMicrophoneInput();

            var model = LanguageUnderstandingModel.FromAppId("7f7a9344-69b6-4582-a01d-19ffa3c9bed8");

            var continuousRecognizer = new SpeechRecognizer(speechConfig, audioConfig);
            var intentRecognizer     = new IntentRecognizer(Intentconfig, audioConfig);

            intentRecognizer.AddAllIntents(model);

            var  synthesizer        = new SpeechSynthesizer(speechConfig);
            bool _waitingForCommand = false;

            continuousRecognizer.Recognized += async(s, e) =>
            {
                if (!_waitingForCommand)
                {
                    if (e.Result.Reason == ResultReason.RecognizedSpeech)
                    {
                        Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");

                        if (e.Result.Text.Contains(WAKE_WORD, StringComparison.CurrentCultureIgnoreCase))
                        {
                            Console.WriteLine($"RECOGNIZED: {WAKE_WORD}");
                            _waitingForCommand = true;
                            await ParseCommand(synthesizer, await awaitCommand(intentRecognizer, synthesizer));

                            _waitingForCommand = false;
                            Console.WriteLine("Listening for wake word.");
                        }
                    }
                }
            };

            await continuousRecognizer.StartContinuousRecognitionAsync();

            Console.Write("Press any key!");
            Console.Read();
        }
Esempio n. 10
0
    private async void RecognizeIntentAsync()
    {
        recognizer = new IntentRecognizer(luisConfig);

        // Creates a Language Understanding model using the app id, and adds specific intents from your model
        var model = LanguageUnderstandingModel.FromAppId(LuisAppId);

        recognizer.AddIntent(model, "changeColor", "changeColor");
        recognizer.AddIntent(model, "moveObject", "moveObject");

        // add event handlers
        recognizer.Recognized  += Recognizer_Recognized;
        recognizer.Recognizing += Recognizer_Recognizing;
        recognizer.Canceled    += Recognizer_Canceled;

        //Start recognizing
        Debug.Log("Say something...");
        await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);
    }
Esempio n. 11
0
        private async Task <SpeechLuisResult> RecognizeSpeechWithIntentRecognizerAsync(string speechFile)
        {
            if (this.LuisConfiguration.IsStaging)
            {
                throw new NotSupportedException("Testing LUIS from speech with the Speech SDK does not currently support the LUIS staging endpoint.");
            }

            var speechConfig = SpeechConfig.FromSubscription(this.LuisConfiguration.SpeechKey, this.LuisConfiguration.SpeechRegion);

            using (var audioInput = AudioConfig.FromWavFileInput(speechFile))
                using (var recognizer = new IntentRecognizer(speechConfig, audioInput))
                {
                    // Add intents to intent recognizer
                    var model = LanguageUnderstandingModel.FromAppId(this.LuisConfiguration.AppId);
                    recognizer.AddIntent(model, "None", "None");
                    var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                    // Checks result.
                    // For some reason RecognizeOnceAsync always return ResultReason.RecognizedSpeech
                    // when intent is recognized. It's because we don't add all possible intents (note that this IS intentional)
                    // in code via AddIntent method.
                    if (result.Reason == ResultReason.RecognizedSpeech || result.Reason == ResultReason.RecognizedIntent)
                    {
                        var content           = result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);
                        var luisResult        = JsonConvert.DeserializeObject <LuisResult>(content);
                        var speechContent     = result.Properties.GetProperty(PropertyId.SpeechServiceResponse_JsonResult);
                        var speechContentJson = JObject.Parse(speechContent);
                        var textScore         = speechContentJson["NBest"]?.Max(t => t.Value <double?>("Confidence"));
                        return(new SpeechLuisResult(luisResult, textScore));
                    }
                    else if (result.Reason == ResultReason.NoMatch)
                    {
                        Logger.LogWarning("Received 'NoMatch' result from Cognitive Services.");
                        return(null);
                    }
                    else
                    {
                        throw new InvalidOperationException($"Failed to get speech recognition result. Reason = '{result.Reason}'");
                    }
                }
        }
        public async Task <Result <LuisResult> > Recognize(string filePath)
        {
            // Credenciais do LUIS
            var config = SpeechConfig.FromSubscription("YourSubscriptionKey", "YourRegion");

            config.SpeechRecognitionLanguage = "pt-br";

            using (var audioInput = AudioConfig.FromWavFileInput(filePath))
            {
                using (var recognizer = new IntentRecognizer(config, audioInput))
                {
                    var model = LanguageUnderstandingModel.FromAppId("YourLuisAppId");
                    recognizer.AddIntent(model, "intent.iot.device_off", "device_off");
                    recognizer.AddIntent(model, "intent.iot.device_on", "device_on");

                    var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                    if (result.Reason == ResultReason.RecognizedIntent)
                    {
                        var js = new DataContractJsonSerializer(typeof(LuisResult));
                        var ms = new MemoryStream(Encoding.UTF8.GetBytes(result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)));
                        return(new Result <LuisResult>((js.ReadObject(ms) as LuisResult)));
                    }
                    else if (result.Reason == ResultReason.NoMatch)
                    {
                        return(new Result <LuisResult>(null, false, "Falha no reconhecimento do áudio!"));
                    }
                    else if (result.Reason == ResultReason.Canceled)
                    {
                        var cancellation = CancellationDetails.FromResult(result);
                        if (cancellation.Reason == CancellationReason.Error)
                        {
                            return(new Result <LuisResult>(null, false, $"Motivo: {cancellation.Reason}. Detalhes: {cancellation.ErrorDetails}"));
                        }
                        return(new Result <LuisResult>(null, false, $"Motivo: {cancellation.Reason}."));
                    }
                }
            }
            return(new Result <LuisResult>(null, false, "Erro desconhecido!"));
        }
Esempio n. 13
0
        static async Task RecognizeIntentAsync()
        {
            //simple speech recognition with intent
            var config = SpeechConfig.FromSubscription(luisKey, luisRegion);

            using (var recognizer = new IntentRecognizer(config))
            {
                var model = LanguageUnderstandingModel.FromAppId(luisAppId);

                //add LUIS intents, you have the option to add only selected intents
                recognizer.AddAllIntents(model);

                Console.WriteLine("Say something...");

                var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                if (result.Reason == ResultReason.RecognizedIntent)
                {
                    Console.WriteLine($"Recognized: Text = {result.Text}");
                    Console.WriteLine($"Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}");
                }
                else if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    Console.WriteLine($"Recognized: Text = {result.Text}");
                    Console.WriteLine("Intent not recognized.");
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    Console.WriteLine("Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"Canceled. Reason = {cancellation.Reason}");
                }
            }
        }
                    public static async Task TextBasedAssistant()
                    {
                        // <intentContinuousRecognitionWithFile>
                        // Creates an instance of a speech config with specified subscription key
                        // and service region. Note that in contrast to other services supported by
                        // the Cognitive Services Speech SDK, the Language Understanding service
                        // requires a specific subscription key from https://www.luis.ai/.
                        // The Language Understanding service calls the required key 'endpoint key'.
                        // Once you've obtained it, replace with below with your own Language Understanding subscription key
                        // and service region (e.g., "westus").
                        var config = SpeechConfig.FromSubscription("", "westus");

                        using (var recognizer = new IntentRecognizer(config))
                        {
                            // Creates a Language Understanding model using the app id, and adds specific intents from your model
                            var model = LanguageUnderstandingModel.FromAppId("");
                            recognizer.AddIntent(model, "DiscoverDealsForTheDay", "id1");
                            recognizer.AddIntent(model, "DiscoverLocation", "id2");
                            recognizer.AddIntent(model, "DiscoverPersonalizedDeals", "id3");
                            recognizer.AddIntent(model, "GoodBye", "id4");
                            recognizer.AddIntent(model, "Greeting", "id5");
                            recognizer.AddIntent(model, "HowToGoToTrialRoom", "id6");
                            recognizer.AddIntent(model, "DiscoverPaymentQueueLength", "id7");

                            // Subscribes to events.
                            recognizer.Recognizing += (s, e) => {
                                //Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
                            };

                            recognizer.Recognized += (s, e) => {
                                if (e.Result.Reason == ResultReason.RecognizedIntent)
                                {
                                    Console.WriteLine($"\nText={e.Result.Text}");
                                    //Console.WriteLine($"    Intent Id: {e.Result.IntentId}.");
                                    string Response = e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);
                                    //Console.Write(Response);
                                    dynamic IntentResponse = JObject.Parse(Response);
                                    dynamic IntentResult   = JObject.Parse(IntentResponse.topScoringIntent.ToString());
                                    string  Intent         = IntentResult.intent.ToString();
                                    Console.WriteLine("Intent: " + Intent);
                                    String TextResult = "";
                                    if (Intent == "Greeting")
                                    {
                                        TextResult = "Hello Suneetha, Welcome back to Shopper's Heaven. Last time you have visited us on Jan 1st ,2019 for some new year offers. How can I help you today ?";
                                    }
                                    else if (Intent == "DiscoverDealsForTheDay")
                                    {
                                        TextResult = "Sure...Give me 2 mins.. We have got great offers for you today. Women and Kids Casual Wears having 40 % discount offers. Women Foot wear section had just launched 60 % clearance sale offer. And cosmetics section is having personalized offer for you";
                                    }
                                    else if (Intent == "DiscoverLocation")
                                    {
                                        TextResult = "Please go till Gate 2 and take the elevator to second floor. You can find Woman's casual wear section on your righthand side";
                                    }
                                    else if (Intent == "HowToGoToTrialRoom")
                                    {
                                        TextResult = "Trail toom is just 200 metres away from you on your left hand side. But looks like all trial rooms are busy now. Please try after 10 mins";
                                    }
                                    else if (Intent == "DiscoverPersonalizedDeals")
                                    {
                                        TextResult = "Please proceed to cosmetic sections at the entrance of second floor. Swith to scan mode in your app and just scan the product that you are interested to buy. You will get Virtual vouchers for that product which you can redeem when you are buying it";
                                    }
                                    else if (Intent == "DiscoverPaymentQueueLength")
                                    {
                                        TextResult = "Its looks good Suneetha. You will be 3rd person in the queue. Please proceed";
                                    }
                                    else if (Intent == "GoodBye")
                                    {
                                        TextResult = "Thanks Suneetha for visiting us again. Hope you enjoyed shopping with me today. See you soon. Last but not least, please do not forget to give feedback about your experience at Shopper Heaven today at the link..";
                                    }
                                    else
                                    {
                                        TextResult = "No Intent Found";
                                    }
                                    Console.WriteLine(TextResult + "\n");
                                    //{
                                    //    "query": "hello",
                                    //      "topScoringIntent": {
                                    //        "intent": "Greeting",
                                    //        "score": 0.9444705
                                    //      },
                                    //      "entities": []
                                    //    }
                                }
                                else if (e.Result.Reason == ResultReason.RecognizedSpeech)
                                {
                                    //Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                                    //Console.WriteLine($"    Intent not recognized.");
                                }
                                else if (e.Result.Reason == ResultReason.NoMatch)
                                {
                                    //Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                                }
                            };

                            recognizer.Canceled += (s, e) => {
                                Console.WriteLine($"CANCELED: Reason={e.Reason}");

                                if (e.Reason == CancellationReason.Error)
                                {
                                    Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
                                    Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                                    Console.WriteLine($"CANCELED: Did you update the subscription info?");
                                }
                            };

                            recognizer.SessionStarted += (s, e) => {
                                //Console.WriteLine("\nSession started");
                            };

                            recognizer.SessionStopped += (s, e) => {
                                //Console.WriteLine("\nSession stopped");
                                //Console.WriteLine("\nStop recognition.");
                            };


                            // Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
                            Console.WriteLine("Say something...");
                            await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                            // Waits for completion.
                            // Use Task.WaitAny to keep the task rooted.

                            do
                            {
                                Console.WriteLine("Press Enter to stop");
                            } while (Console.ReadKey().Key != ConsoleKey.Enter);

                            // Stops recognition.
                            await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
                        }
                    }
        // Continuous intent recognition using file input.
        public static async Task ContinuousRecognitionWithFileAsync()
        {
            // <intentContinuousRecognitionWithFile>
            // Creates an instance of a speech factory with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Service Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            var factory = SpeechFactory.FromSubscription("YourLanguageUnderstandingSubscriptionKey", "YourLanguageUnderstandingServiceRegion");

            // Creates an intent recognizer using file as audio input.
            // Replace with your own audio file name.
            using (var recognizer = factory.CreateIntentRecognizerWithFileInput("whatstheweatherlike.wav"))
            {
                // The TaskCompletionSource to stop recognition.
                var stopRecognition = new TaskCompletionSource <int>();

                // Creates a Language Understanding model using the app id, and adds specific intents from your model
                var model = LanguageUnderstandingModel.FromAppId("YourLanguageUnderstandingAppId");
                recognizer.AddIntent("id1", model, "YourLanguageUnderstandingIntentName1");
                recognizer.AddIntent("id2", model, "YourLanguageUnderstandingIntentName2");
                recognizer.AddIntent("any-IntentId-here", model, "YourLanguageUnderstandingIntentName3");

                // Subscribes to events.
                recognizer.IntermediateResultReceived += (s, e) => {
                    Console.WriteLine($"\n    Partial result: {e.Result.Text}.");
                };

                recognizer.FinalResultReceived += (s, e) => {
                    if (e.Result.RecognitionStatus == RecognitionStatus.Recognized)
                    {
                        Console.WriteLine($"\n    Final result: Status: {e.Result.RecognitionStatus.ToString()}, Text: {e.Result.Text}.");
                        Console.WriteLine($"\n    Intent Id: {e.Result.IntentId}.");
                        Console.WriteLine($"\n    Language Understanding JSON: {e.Result.Properties.Get<string>(ResultPropertyKind.LanguageUnderstandingJson)}.");
                    }
                    else
                    {
                        Console.WriteLine($"\n    Final result: Status: {e.Result.RecognitionStatus.ToString()}, FailureReason: {e.Result.RecognitionFailureReason}.");
                    }
                };

                recognizer.RecognitionErrorRaised += (s, e) => {
                    Console.WriteLine($"\n    An error occurred. Status: {e.Status.ToString()}, FailureReason: {e.FailureReason}");
                    stopRecognition.TrySetResult(0);
                };

                recognizer.OnSessionEvent += (s, e) => {
                    Console.WriteLine($"\n    Session event. Event: {e.EventType.ToString()}.");
                    // Stops recognition when session stop is detected.
                    if (e.EventType == SessionEventType.SessionStoppedEvent)
                    {
                        Console.WriteLine($"\nStop recognition.");
                        stopRecognition.TrySetResult(0);
                    }
                };

                // Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
                Console.WriteLine("Say something...");
                await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                // Waits for completion.
                // Use Task.WaitAny to keep the task rooted.
                Task.WaitAny(new[] { stopRecognition.Task });

                // Stops recognition.
                await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
            }
            // </intentContinuousRecognitionWithFile>
        }
Esempio n. 16
0
        static async Task ContinuousRecognizeIntentAsync()
        {
            //continuous speech recognition and detect intent
            var config = SpeechConfig.FromSubscription(luisKey, luisRegion);

            using (var recognizer = new IntentRecognizer(config))
            {
                var stopRecognition = new TaskCompletionSource <int>();

                var model = LanguageUnderstandingModel.FromAppId(luisAppId);
                recognizer.AddAllIntents(model);

                recognizer.Recognizing += (s, e) =>
                {
                    Console.WriteLine($"Recognizing: Text = {e.Result.Text}");
                };

                recognizer.Recognized += (s, e) =>
                {
                    if (e.Result.Reason == ResultReason.RecognizedIntent)
                    {
                        Console.WriteLine($"Recognized: Text = {e.Result.Text}");
                        LUIS.GetLuisResult(e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult));
                        string intent = LUIS.GetLuisIntent(e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult));
                        LUIS.ResponseToLuisIntent(intent, e.Result.Text);
                    }

                    else if (e.Result.Reason == ResultReason.RecognizedSpeech)
                    {
                        Console.WriteLine($"Recognized: Text = {e.Result.Text}");
                        Console.WriteLine("Intent not recognized.");
                    }
                };

                recognizer.Canceled += (s, e) =>
                {
                    Console.WriteLine($"Canceled: Reason={e.Reason}");
                    if (e.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                    stopRecognition.TrySetResult(0);
                };

                recognizer.SessionStarted += (s, e) =>
                {
                    Console.WriteLine("\n Session started event.");
                };

                recognizer.SessionStopped += (s, e) =>
                {
                    Console.WriteLine("\n Session stopped.");
                    stopRecognition.TrySetResult(0);
                };

                Console.WriteLine("[Continous Recognition] Say something...");
                await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                do
                {
                    Console.WriteLine("Press Enter to stop");
                } while (Console.ReadKey().Key != ConsoleKey.Enter);

                await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
            }
        }
        // Continuous intent recognition using file input.
        public static async Task ContinuousRecognitionWithFileAsync()
        {
            // <intentContinuousRecognitionWithFile>
            // Creates an instance of a speech config with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Services Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            var config = SpeechConfig.FromSubscription("YourLanguageUnderstandingSubscriptionKey", "YourLanguageUnderstandingServiceRegion");

            // Creates an intent recognizer using file as audio input.
            // Replace with your own audio file name.
            using (var audioInput = AudioConfig.FromWavFileInput("whatstheweatherlike.wav"))
            {
                using (var recognizer = new IntentRecognizer(config, audioInput))
                {
                    // The TaskCompletionSource to stop recognition.
                    var stopRecognition = new TaskCompletionSource <int>();

                    // Creates a Language Understanding model using the app id, and adds specific intents from your model
                    var model = LanguageUnderstandingModel.FromAppId("YourLanguageUnderstandingAppId");
                    recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName1", "id1");
                    recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName2", "id2");
                    recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName3", "any-IntentId-here");

                    // Subscribes to events.
                    recognizer.Recognizing += (s, e) => {
                        Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
                    };

                    recognizer.Recognized += (s, e) => {
                        if (e.Result.Reason == ResultReason.RecognizedIntent)
                        {
                            Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                            Console.WriteLine($"    Intent Id: {e.Result.IntentId}.");
                            Console.WriteLine($"    Language Understanding JSON: {e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
                        }
                        else if (e.Result.Reason == ResultReason.RecognizedSpeech)
                        {
                            Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                            Console.WriteLine($"    Intent not recognized.");
                        }
                        else if (e.Result.Reason == ResultReason.NoMatch)
                        {
                            Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                        }
                    };

                    recognizer.Canceled += (s, e) => {
                        Console.WriteLine($"CANCELED: Reason={e.Reason}");

                        if (e.Reason == CancellationReason.Error)
                        {
                            Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                            Console.WriteLine($"CANCELED: Did you update the subscription info?");
                        }

                        stopRecognition.TrySetResult(0);
                    };

                    recognizer.SessionStarted += (s, e) => {
                        Console.WriteLine("\n    Session started event.");
                    };

                    recognizer.SessionStopped += (s, e) => {
                        Console.WriteLine("\n    Session stopped event.");
                        Console.WriteLine("\nStop recognition.");
                        stopRecognition.TrySetResult(0);
                    };


                    // Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
                    Console.WriteLine("Say something...");
                    await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                    // Waits for completion.
                    // Use Task.WaitAny to keep the task rooted.
                    Task.WaitAny(new[] { stopRecognition.Task });

                    // Stops recognition.
                    await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
                }
            }
            // </intentContinuousRecognitionWithFile>
        }
Esempio n. 18
0
        public static async Task RecognizeIntentAsync()
        {
            // </skeleton_1>
            // Creates an instance of a speech config with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Services Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            // The default language is "en-us".
            // <create_speech_configuration>
            var config = SpeechConfig.FromSubscription(
                "YourLanguageUnderstandingSubscriptionKey",
                "YourLanguageUnderstandingServiceRegion");

            // </create_speech_configuration>

            // <create_intent_recognizer_1>
            // Creates an intent recognizer using microphone as audio input.
            using (var recognizer = new IntentRecognizer(config))
            {
                // </create_intent_recognizer_1>

                // <add_intents>
                // Creates a Language Understanding model using the app id, and adds specific intents from your model
                var model = LanguageUnderstandingModel.FromAppId("YourLanguageUnderstandingAppId");
                recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName1", "id1");
                recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName2", "id2");
                recognizer.AddIntent(model, "YourLanguageUnderstandingIntentName3", "any-IntentId-here");
                // </add_intents>

                // To add all of the possible intents from a LUIS model to the recognizer, uncomment the line below:
                // recognizer.AddAllIntents(model);

                // <recognize_intent>
                // Starts recognizing.
                Console.WriteLine("Say something...");

                // Starts intent recognition, and returns after a single utterance is recognized. The end of a
                // single utterance is determined by listening for silence at the end or until a maximum of 15
                // seconds of audio is processed.  The task returns the recognition text as result.
                // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
                // shot recognition like command or query.
                // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
                var result = await recognizer.RecognizeOnceAsync();

                // </recognize_intent>

                // <print_results>
                // Checks result.
                switch (result.Reason)
                {
                case ResultReason.RecognizedIntent:
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent Id: {result.IntentId}.");
                    var json = result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);
                    Console.WriteLine($"    Language Understanding JSON: {json}.");
                    break;

                case ResultReason.RecognizedSpeech:
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent not recognized.");
                    break;

                case ResultReason.NoMatch:
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                    break;

                case ResultReason.Canceled:
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                    break;
                }
                // </print_results>
                // <create_intent_recognizer_2>
            }
            // </create_intent_recognizer_2>
            // <skeleton_2>
        }
Esempio n. 19
0
        public static async Task RecognizeSpeechAsync()
        {
            // Create an instance of a speech config with the specified app key and region.
            var config = SpeechConfig.FromSubscription(YourAppKey, YourRegion);

            // Use the microphone as input.
            var audioConfig = AudioConfig.FromDefaultMicrophoneInput();

            var stopRecognition = new TaskCompletionSource <int>();

            // Create a new IntentRecognizer, which uses the config and the audioConfig.
            using (var recognizer = new IntentRecognizer(config, audioConfig))
            {
                // Create a Language Understanding model using the app id.
                var model = LanguageUnderstandingModel.FromAppId(YourAppId);

                // Add the intents which are specified by the LUIS app.
                recognizer.AddIntent(model, "HomeAutomation.TurnOff", "off");
                recognizer.AddIntent(model, "HomeAutomation.TurnOn", "on");

                // Subscribe to events.
                recognizer.Recognizing += (s, e) =>
                {
                    Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
                };

                recognizer.Recognized += (s, e) =>
                {
                    // The LUIS app recognized an intent.
                    if (e.Result.Reason == ResultReason.RecognizedIntent)
                    {
                        // Get the result from the event arguments and print it into the console.
                        var responseJson = e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);

                        Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                        Console.WriteLine($"    Intent Id: {e.Result.IntentId}.");
                        Console.WriteLine($"    Language Understanding JSON: {responseJson}.");

                        // Deserialize the JSON result into an object.
                        var responseObject = JsonConvert.DeserializeObject <SpeechResponse>(responseJson);

                        // Get the intent out of the result. This gives us the command.
                        var intent = responseObject.topScoringIntent.intent;
                        if (intent == "HomeAutomation.TurnOn")
                        {
                            intent = "on";
                        }
                        else if (intent == "HomeAutomation.TurnOff")
                        {
                            intent = "off";
                        }

                        // Get the colour entity out of the result.
                        var colourEntity = responseObject.entities.FirstOrDefault(x => x.type == "Colour");
                        var colour       = colourEntity.entity;

                        // Create the request we will send to the web API.
                        var request = new SpeechRequest
                        {
                            Colour  = colour,
                            Command = intent
                        };

                        // Create a new HttpClient and send the request.
                        var client  = new HttpClient();
                        var content = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json");

                        client.PostAsync("http://<your-local-raspberrypi-ip>/api/Speech", content);
                    }

                    // The speech service recognized speech.
                    else if (e.Result.Reason == ResultReason.RecognizedSpeech)
                    {
                        Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                        Console.WriteLine($"    Intent not recognized.");
                    }

                    // The input has not been recognized.
                    else if (e.Result.Reason == ResultReason.NoMatch)
                    {
                        Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                    }
                };

                recognizer.Canceled += (s, e) =>
                {
                    Console.WriteLine($"CANCELED: Reason={e.Reason}");

                    if (e.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }

                    stopRecognition.TrySetResult(0);
                };

                recognizer.SessionStarted += (s, e) =>
                {
                    Console.WriteLine("\n    Session started event.");
                };

                recognizer.SessionStopped += (s, e) =>
                {
                    Console.WriteLine("\n    Session stopped event.");
                    Console.WriteLine("\nStop recognition.");
                    stopRecognition.TrySetResult(0);
                };

                // Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
                await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                // Waits for completion.
                // Use Task.WaitAny to keep the task rooted.
                Task.WaitAny(new[] { stopRecognition.Task });

                // Stops recognition.
                await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
            }
        }
Esempio n. 20
0
        private async static Task RecognizeSpeechAndIntentAsync()
        {
            var config = SpeechConfig.FromEndpoint(
                new Uri("https://eastus2.api.cognitive.microsoft.com/sts/v1.0/issuetoken"),
                "MySuscriptionKey");

            config.SpeechRecognitionLanguage = "es-ES";

            using var speechRecognition = new IntentRecognizer(config);

            var luisModel = LanguageUnderstandingModel.FromAppId("ba417c40-bb51-4704-966a-f9c58afaf1c8");

            speechRecognition.AddAllIntents(luisModel);
            speechRecognition.AddIntent("chao");

            var endRecognition = new TaskCompletionSource <int>();

            speechRecognition.Recognized += (s, e) =>
            {
                switch (e.Result.Reason)
                {
                case ResultReason.NoMatch:
                    if (!endRecognition.Task.IsCompleted)
                    {
                        Console.WriteLine($"No entendí na':{e.Result.Text}");
                    }
                    break;

                case ResultReason.Canceled:
                    Console.WriteLine($"Se canceló la escucha:{e.Result.Text}");
                    break;

                case ResultReason.RecognizingSpeech:
                    Console.WriteLine($"Escuchando:{e.Result.Text}");
                    break;

                case ResultReason.RecognizedSpeech:
                    Console.WriteLine($"Entendí esto:{e.Result.Text}");
                    break;

                case ResultReason.RecognizedIntent:
                    Console.WriteLine($"Detectado comando de voz:{e.Result.Text}");
                    Console.WriteLine($"Saliendo ....");
                    endRecognition.TrySetResult(0);
                    break;

                default:
                    Console.WriteLine($"LLegué aquí porque:{e.Result.Reason}");
                    break;
                }
            };

            speechRecognition.Canceled += (s, e) =>
            {
                if (e.Reason == CancellationReason.Error)
                {
                    Console.WriteLine($"ocurrió un error:{e.ErrorCode} => {e.ErrorDetails}");
                }

                endRecognition.TrySetResult(0);
            };

            speechRecognition.SessionStopped += (s, e) =>
            {
                Console.WriteLine("Deteniendo");
                endRecognition.TrySetResult(0);
            };

            Console.WriteLine("Ahora empieza a hablar...");
            await speechRecognition.StartContinuousRecognitionAsync().ConfigureAwait(false);

            Task.WaitAny(new[] { endRecognition.Task });
            await speechRecognition.StopContinuousRecognitionAsync().ConfigureAwait(false);
        }
        static async Task RecognizeIntentAsync()
        {
            // Creates an instance of a speech config with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Services Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            // The default language is "en-us".
            var config = SpeechConfig.FromSubscription("YourLanguageUnderstandingSubscriptionKey", "YourLanguageUnderstandingServiceRegion");

            // Creates an intent recognizer using microphone as audio input.
            using (var recognizer = new IntentRecognizer(config))
            {
                // Creates a Language Understanding model using the app id, and adds specific intents from your model
                var model = LanguageUnderstandingModel.FromAppId("YourLanguageUnderstandingAppId");
                recognizer.AddIntent(model, "HomeAutomation.TurnOff", "off");
                recognizer.AddIntent(model, "HomeAutomation.TurnOn", "on");

                // Starts recognizing.
                Console.WriteLine("Say something...");

                // Starts intent recognition, and returns after a single utterance is recognized. The end of a
                // single utterance is determined by listening for silence at the end or until a maximum of 15
                // seconds of audio is processed.  The task returns the recognition text as result.
                // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
                // shot recognition like command or query.
                // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
                var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                // Checks result.
                if (result.Reason == ResultReason.RecognizedIntent)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent Id: {result.IntentId}.");
                    Console.WriteLine($"    Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
                }
                else if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent not recognized.");
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                }
            }
        }
Esempio n. 22
0
        // Intent recognition in the specified language, using microphone.
        public async Task <String> RecognitionWithMicrophoneUsingLanguageAsync()
        {
            log.Info("ENTER - RecognitionWithMicrophoneUsingLanguageAsync");
            // Creates an instance of a speech config with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Services Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            var config   = SpeechConfig.FromSubscription(subscriptionKey, serviceRegion);
            var language = "es-mx";

            config.SpeechRecognitionLanguage = language;

            // Creates an intent recognizer in the specified language using microphone as audio input.
            using (var recognizer = new IntentRecognizer(config))
            {
                // Creates a Language Understanding model using the app id, and adds specific intents from your model
                var model = LanguageUnderstandingModel.FromAppId(appId);
                recognizer.AddIntent(model, "Greetings", "Greetings");
                recognizer.AddIntent(model, "None", "None");
                recognizer.AddIntent(model, "Ubicacion", "Ubicacion");
                recognizer.AddIntent(model, "Despedida", "Despedida");
                recognizer.AddIntent(model, "Compras", "Compras");
                recognizer.AddIntent(model, "Descuento", "Descuento");



                // Starts recognizing.
                log.Debug("Say something in " + language + "...");

                // Starts speech recognition, and returns after a single utterance is recognized. The end of a
                // single utterance is determined by listening for silence at the end or until a maximum of 15
                // seconds of audio is processed.  The task returns the recognition text as result.
                // Note: Since RecognizeOnceAsync() returns only a single utterance, it is suitable only for single
                // shot recognition like command or query.
                // For long-running multi-utterance recognition, use StartContinuousRecognitionAsync() instead.
                var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                // Checks result.
                if (result.Reason == ResultReason.RecognizedIntent)
                {
                    log.Debug($"RECOGNIZED: Text={result.Text}");
                    log.Debug($"    Intent Id: {result.IntentId}.");
                    log.Debug($"    Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");

                    //  Updating MessageArea
                    Demo_ChinaTown.MainWindow.AppWindow.MessageArea.Dispatcher.Invoke((Action) delegate
                    {
                        Demo_ChinaTown.MainWindow.AppWindow.MessageArea.Text += $"\nUsuario: {result.Text}";
                    });

                    return(result.IntentId);
                }
                else if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    log.Debug($"RECOGNIZED: Text={result.Text}");
                    log.Debug($"    Intent not recognized.");
                    return("Intent not recognized.");
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    log.Debug($"NOMATCH: Speech could not be recognized.");
                    return("Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    log.Debug($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        log.Debug($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                        log.Debug($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        log.Debug($"CANCELED: Did you update the subscription info?");
                    }
                }
                return(null);
            }
        }
        public static async Task RecognizeSpeechAsync()
        {
            initMqttClient(mqttBrokerAddress);
            // Creates an instance of a speech config with specified subscription key and service region.
            // Replace with your own subscription key // and service region (e.g., "westus").
            var intentConfig = SpeechConfig.FromSubscription("", "westus2");

            // Creates a speech recognizer.
            using (var intentRecognizer = new IntentRecognizer(intentConfig))
            {
                // The TaskCompletionSource to stop recognition.
                var stopRecognition = new TaskCompletionSource <int>();

                var model = LanguageUnderstandingModel.FromAppId("");
                intentRecognizer.AddAllIntents(model);

                // Subscribes to events.
                intentRecognizer.Recognizing += (s, e) => {
                    Console.WriteLine($"RECOGNIZING: Text={e.Result.Text}");
                };

                intentRecognizer.Recognized += (s, e) => {
                    if (e.Result.Reason == ResultReason.RecognizedIntent)
                    {
                        Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                        Console.WriteLine($"    Intent Id: {e.Result.IntentId}.");
                        Console.WriteLine($"    Language Understanding JSON: {e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
                        if (e.Result.IntentId == "FollowPerson")
                        {
                            var     jsonResult = e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult);
                            dynamic stuff      = JObject.Parse(jsonResult);
                            try
                            {
                                string name = stuff.entities[0].entity;
                                Console.WriteLine(name);
                                int id = nameToIdDict.GetValueOrDefault(name);
                                mqttClient.Publish("bcx19-seek-the-geek/tag/control", Encoding.UTF8.GetBytes($"target.{name}"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                                Console.WriteLine("MQTT Message sent");
                            }
                            catch
                            {
                                Console.WriteLine("Error");
                            }
                        }
                        else if (e.Result.IntentId == "Rover.Stop")
                        {
                            mqttClient.Publish("bcx19-seek-the-geek/tag/control", Encoding.UTF8.GetBytes("rover.stop"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            Console.WriteLine("MQTT Message sent");
                        }
                        else if (e.Result.IntentId == "Rover.Start")
                        {
                            mqttClient.Publish("bcx19-seek-the-geek/tag/control", Encoding.UTF8.GetBytes("rover.start"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            Console.WriteLine("MQTT Message sent");
                        }
                        else if (e.Result.IntentId == "Rover.Left")
                        {
                            mqttClient.Publish("bcx19-seek-the-geek/tag/control", Encoding.UTF8.GetBytes("rover.left"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            Console.WriteLine("MQTT Message sent");
                        }
                        else if (e.Result.IntentId == "Rover.Right")
                        {
                            mqttClient.Publish("bcx19-seek-the-geek/tag/control", Encoding.UTF8.GetBytes("rover.right"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            Console.WriteLine("MQTT Message sent");
                        }
                        else if (e.Result.IntentId == "Rover.Exit")
                        {
                            mqttClient.Publish("bcx19-seek-the-geek/tag/control", Encoding.UTF8.GetBytes("rover.exit"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            Console.WriteLine("MQTT Message sent");
                        }
                        else if (e.Result.IntentId == "Rover.Back")
                        {
                            mqttClient.Publish("bcx19-seek-the-geek/tag/control", Encoding.UTF8.GetBytes("rover.back"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false);
                            Console.WriteLine("MQTT Message sent");
                        }
                    }
                    else if (e.Result.Reason == ResultReason.RecognizedSpeech)
                    {
                        Console.WriteLine($"RECOGNIZED: Text={e.Result.Text}");
                        Console.WriteLine($"    Intent not recognized.");
                    }
                    else if (e.Result.Reason == ResultReason.NoMatch)
                    {
                        Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                    }
                };

                intentRecognizer.Canceled += (s, e) => {
                    Console.WriteLine($"CANCELED: Reason={e.Reason}");

                    if (e.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }

                    stopRecognition.TrySetResult(0);
                };

                intentRecognizer.SessionStarted += (s, e) => {
                    Console.WriteLine("\n    Session started event.");
                };

                intentRecognizer.SessionStopped += (s, e) => {
                    Console.WriteLine("\n    Session stopped event.");
                    Console.WriteLine("\nStop recognition.");
                    stopRecognition.TrySetResult(0);
                };


                // Starts continuous recognition. Uses StopContinuousRecognitionAsync() to stop recognition.
                Console.WriteLine("Say something...");
                await intentRecognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                // Waits for completion.
                // Use Task.WaitAny to keep the task rooted.
                Task.WaitAny(new[] { stopRecognition.Task });

                // Stops recognition.
                await intentRecognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
            }
        }
Esempio n. 24
0
        static async Task RecognizeAsync()
        {
            string LUIS_assigned_endpoint_key = "<LUIS-assigned-resource-key>";
            string LUIS_endpoint_key_region   = "westus";
            string LUIS_app_ID = "<LUIS-app-ID>";

            // Creates an instance of a speech config with specified subscription key
            // and service region. Note that in contrast to other services supported by
            // the Cognitive Services Speech SDK, the Language Understanding service
            // requires a specific subscription key from https://www.luis.ai/.
            // The Language Understanding service calls the required key 'endpoint key'.
            // Once you've obtained it, replace with below with your own Language Understanding subscription key
            // and service region (e.g., "westus").
            // The default language is "en-us".
            var config = SpeechConfig.FromSubscription(LUIS_assigned_endpoint_key, LUIS_endpoint_key_region);

            // Creates an intent recognizer using microphone as audio input.
            using (var recognizer = new IntentRecognizer(config))
            {
                // Creates a Language Understanding model using the app id, and adds specific intents from your model
                var model = LanguageUnderstandingModel.FromAppId(LUIS_app_ID);

                // Add intents from HumanResources.json to your intent recognizer
                recognizer.AddIntent(model, "None", "None");
                recognizer.AddIntent(model, "FindForm", "FindForm");
                recognizer.AddIntent(model, "GetEmployeeBenefits", "GetEmployeeBenefits");
                recognizer.AddIntent(model, "GetEmployeeOrgChart", "GetEmployeeOrgChart");
                recognizer.AddIntent(model, "MoveAssetsOrPeople", "MoveAssetsOrPeople");

                // Starts recognizing.
                Console.WriteLine("Say something...");

                // Performs recognition. RecognizeOnceAsync() returns when the first utterance has been recognized,
                // so it is suitable only for single shot recognition like command or query. For long-running
                // recognition, use StartContinuousRecognitionAsync() instead.
                var result = await recognizer.RecognizeOnceAsync().ConfigureAwait(false);

                // Checks result.
                if (result.Reason == ResultReason.RecognizedIntent)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent Id: {result.IntentId}.");
                    Console.WriteLine($"    Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
                }
                else if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent not recognized.");
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                }
            }
        }
Esempio n. 25
0
        public static void Main(string [] args)
        {
            //CONFIG LUIS
            configLuis = SpeechConfig.FromSubscription("b1ea9c02d3954e9f9cf90592f9062ef6", "westus2");
            configLuis.SpeechRecognitionLanguage = "pt-BR";

            //CONFIG SPEECH
            configSpeech = SpeechConfig.FromSubscription("9184b21db9b743bd83770061b376ee2c", "westus2");
            configSpeech.SpeechSynthesisVoiceName = "Microsoft Server Speech Text to Speech Voice (pt-BR, FranciscaNeural)";

            //ADICIONANDO AS INTENCOES CRIADAS NO LUIS
            recognizer = new IntentRecognizer(configLuis);
            model      = LanguageUnderstandingModel.FromAppId("2940577d-15f2-42bb-a07f-a760cd651c0b");
            recognizer.AddIntent(model, "AvisarChegada", "avisar_chegada");
            recognizer.AddIntent(model, "Cumprimento", "cumprimento");
            recognizer.AddIntent(model, "Despedida", "despedida");
            recognizer.AddIntent(model, "Entregar", "entregar");
            recognizer.AddIntent(model, "Visita", "visitar");
            recognizer.AddIntent(model, "InformarDestino", "destino");
            recognizer.AddIntent(model, "AutorizarVisitante", "autorizado");
            recognizer.AddIntent(model, "NaoAutorizarVisitante", "nao_autorizado");

            synthesizer = new SpeechSynthesizer(configSpeech);

            //LÊ AS REGRAS DEFINIDAS NO ARQUIVO XML
            leitorXML = new Leitor();
            leitorXML.LeArquivoXML();

            //VALIDA AS VARIAVEIS E REGRAS LIDAS NO ARQUIVO ATRAVES DO PROCESSADOR LOGICO
            processador = new Processador();

            while (controle_interacao)
            {
                try
                {
                    if (estado == 2 || estado == 3 || estado == 4)
                    {
                        controle_interacao = false;
                        ligacao_morador();
                    }
                    else if (estado == 6)
                    {
                        despedida();
                    }
                    else
                    {
                        RecognizeIntentAsync().Wait();
                    }
                }
                catch
                {
                    if (timeout == 0)
                    {
                        Resposta("Olá, tem alguém me escutando?").Wait();
                    }

                    else if (timeout == 1)
                    {
                        Resposta("Olá, ainda tem alguém aí?").Wait();
                    }

                    else if (timeout == 2)
                    {
                        Resposta("Encerrando a chamada").Wait();
                        controle_interacao = false;
                    }

                    timeout++;
                }
            }
        }
Esempio n. 26
0
        private async void ConfigureIntentRecognizer()
        {
            var config = SpeechConfig.FromSubscription("e4c237841b7043b9b2c73a432a85416c", "westus");

            config.SpeechRecognitionLanguage = "es-es";
            var stopRecognition = new TaskCompletionSource <int>();

            using (recognizer = new IntentRecognizer(config))
            {
                var model = LanguageUnderstandingModel.FromAppId("ce892100-78a7-48b0-8e09-5dc18b16996d");
                recognizer.AddAllIntents(model, "Id1");

                recognizer.Recognized += async(s, e) =>
                {
                    await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                    {
                        //recognizedText.Text = e.Result.Text;

                        //var prediction = predictionResult.Prediction;
                        //MyMessageBox(prediction.TopIntent);
                    });

                    try
                    {
                        var predictionResult = GetPredictionAsync(e.Result.Text).Result;
                        var prediction       = predictionResult.Prediction;


                        if (prediction.TopIntent == "None")
                        {
                            await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                recognizedText.Text = "No entiendo la acción que me pides.";
                            });

                            muestraHora  = false;
                            muestraTexto = false;
                        }
                        else if (prediction.TopIntent == "MuestraHora")
                        {
                            await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                var now = DateTime.Now;
                                //recognizedText.Text = now.ToString("HH:mm");
                                recognizedText.Text = "Son las " + now.Hour + ":" + now.Minute + ".";
                            });

                            muestraHora  = true;
                            muestraTexto = false;
                        }
                        else if (prediction.TopIntent == "EscribeTexto")
                        {
                            await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                                                     {;
                                                                      recognizedText.Text = "Esto es un texto."; });

                            muestraTexto = true;
                            muestraHora  = false;
                        }
                        else if (prediction.TopIntent == "OcultaHora")
                        {
                            await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                if (muestraHora)
                                {
                                    recognizedText.Text = "Hora oculta.";
                                    muestraHora         = false;
                                    muestraTexto        = false;
                                }
                            });
                        }
                        else if (prediction.TopIntent == "OcultaTexto")
                        {
                            await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                if (muestraTexto)
                                {
                                    recognizedText.Text = "Texto ocultado.";
                                    muestraHora         = false;
                                    muestraTexto        = false;
                                }
                            });
                        }
                        else if (prediction.TopIntent == "CambioColor")
                        {
                            string color = "";
                            await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                            {
                                //string item = prediction.Entities.First().Value.ToString();
                                color = prediction.Entities.First().Value.ToString().Replace(System.Environment.NewLine, "");
                                color = color.Replace("[", "");
                                color = color.Replace("]", "");
                                color = color.Replace("\"", "");
                                color = color.Replace(" ", "");
                                recognizedText.Text = "Estableciendo fondo de color " + color + ".";
                                muestraHora         = false;
                                muestraTexto        = false;
                            });

                            try
                            {
                                if (colors.ContainsKey(color))
                                {
                                    await rectangle.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                                    {
                                        rectangle.Fill = new SolidColorBrush(colors[color]);
                                    });
                                }
                            }
                            catch (NullReferenceException) { }
                        }
                    }
                    catch (System.AggregateException)
                    {
                    }

                    /*if (e.Result.Reason == ResultReason.RecognizedIntent)
                     * {
                     *
                     *  var jsonResponse = JObject.Parse(e.Result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult));
                     *  await textJson.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                     *  {
                     *      textJson.Text = jsonResponse.ToString();
                     *  });
                     *  var intent = jsonResponse.SelectToken("topScoringIntent.intent").ToString();
                     *
                     *  if (intent.Equals("CambioColor"))
                     *  {
                     *      try
                     *      {
                     *          string color = jsonResponse.SelectToken("$..entities[?(@.type=='Color')].entity").ToString();
                     *          if (colors.ContainsKey(color))
                     *              await rectangle.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                     *              {
                     *                  rectangle.Fill = new SolidColorBrush(colors[color]);
                     *              });
                     *      }
                     *      catch (NullReferenceException) { }
                     *
                     *
                     *
                     *  }
                     *
                     *
                     * }
                     * else if (e.Result.Reason == ResultReason.RecognizedSpeech)
                     * {
                     *  await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                     *  {
                     *      recognizedText.Text = e.Result.Text;
                     *  });
                     * }
                     * else if (e.Result.Reason == ResultReason.NoMatch)
                     * {
                     *  await recognizedText.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                     *  {
                     *      recognizedText.Text = "Speech could not be recognized.";
                     *  });
                     * }*/
                };

                recognizer.Canceled += (s, e) =>
                {
                    Console.WriteLine($"CANCELED: Reason={e.Reason}");

                    if (e.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={e.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={e.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                };

                recognizer.SessionStopped += (s, e) =>
                {
                    Console.WriteLine("\n    Session stopped event.");
                    Console.WriteLine("\nStop recognition.");
                    stopRecognition.TrySetResult(0);
                };

                Console.WriteLine("Say something...");
                await recognizer.StartContinuousRecognitionAsync().ConfigureAwait(false);

                // Waits for completion.
                // Use Task.WaitAny to keep the task rooted.
                Task.WaitAny(new[] { stopRecognition.Task });

                // Stops recognition.
                await recognizer.StopContinuousRecognitionAsync().ConfigureAwait(false);
            }
        }
Esempio n. 27
0
        public static async Task RecognizeOnceSpeechAsync(SpeechTranslationConfig config)
        {
            var allCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);

            // Creates a speech recognizer.
            using (var recognizer = new IntentRecognizer(config))
            {
                Console.WriteLine("Say something...");

                var model = LanguageUnderstandingModel.FromAppId(ConfigurationManager.AppSettings.Get("LUISId"));
                recognizer.AddAllIntents(model);

                var result = await recognizer.RecognizeOnceAsync();

                // Checks result.
                if (result.Reason == ResultReason.RecognizedIntent)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent Id: {result.IntentId}.");
                    Console.WriteLine($"    Language Understanding JSON: {result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult)}.");
                    if (result.IntentId == "Translate")
                    {
                        var    luisJson  = JObject.Parse(result.Properties.GetProperty(PropertyId.LanguageUnderstandingServiceResponse_JsonResult));
                        string targetLng = luisJson["entities"].First(x => x["type"].ToString() == "TargetLanguage")["entity"].ToString();
                        string text      = luisJson["entities"].First(x => x["type"].ToString() == "Text")["entity"].ToString();

                        var lng = allCultures.FirstOrDefault(c => c.DisplayName.ToLower() == targetLng.ToLower()) ??
                                  allCultures.FirstOrDefault(c => c.DisplayName.ToLower() == "english");
                        var translated = Translate.TranslateText("de-DE", text);

                        Console.WriteLine("Translation: " + translated);

                        var synth = new System.Speech.Synthesis.SpeechSynthesizer();

                        // Configure the audio output.
                        synth.SetOutputToDefaultAudioDevice();

                        // Speak a string.
                        synth.SelectVoice(synth.GetInstalledVoices().First(x => x.VoiceInfo.Culture.TwoLetterISOLanguageName == lng.TwoLetterISOLanguageName).VoiceInfo.Name);
                        synth.Speak(translated);
                    }
                }
                else if (result.Reason == ResultReason.RecognizedSpeech)
                {
                    Console.WriteLine($"RECOGNIZED: Text={result.Text}");
                    Console.WriteLine($"    Intent not recognized.");
                }
                else if (result.Reason == ResultReason.NoMatch)
                {
                    Console.WriteLine($"NOMATCH: Speech could not be recognized.");
                }
                else if (result.Reason == ResultReason.Canceled)
                {
                    var cancellation = CancellationDetails.FromResult(result);
                    Console.WriteLine($"CANCELED: Reason={cancellation.Reason}");

                    if (cancellation.Reason == CancellationReason.Error)
                    {
                        Console.WriteLine($"CANCELED: ErrorCode={cancellation.ErrorCode}");
                        Console.WriteLine($"CANCELED: ErrorDetails={cancellation.ErrorDetails}");
                        Console.WriteLine($"CANCELED: Did you update the subscription info?");
                    }
                }
            }
        }