public void BadRequestSnippet()
        {
            string endpoint        = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT");
            string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");

            var    credentials = new TextAnalyticsSubscriptionKeyCredential(subscriptionKey);
            var    client      = new TextAnalyticsClient(new Uri(endpoint), credentials);
            string input       = "Este documento está en español.";

            #region Snippet:BadRequest
            try
            {
                DetectLanguageResult result = client.DetectLanguage(input);
            }
            catch (RequestFailedException e)
            {
                Console.WriteLine(e.ToString());
            }
            #endregion
        }
Exemplo n.º 2
0
        private async Task DetectLanguageAsync()
        {
            try
            {
                if (!string.IsNullOrEmpty(this.speechRecognitionTextBox.Text))
                {
                    DetectLanguageResult textDetectResult = await TextAnalyticsHelper.GetDetectedLanguageAsync(this.speechRecognitionTextBox.Text);

                    this.detectedLanguage = new string[] { textDetectResult.Language["iso6391Name"], textDetectResult.Language["name"] };
                }
                else
                {
                    this.detectedLanguage = new string[] { "en", string.Empty };
                }
            }
            catch (Exception ex)
            {
                await Util.GenericApiCallExceptionHandler(ex, "Error during Text Analytics 'Detect' call.");
            }
        }