Language Detection using Text Analytics API 2.0 Cognitive Service

Posted by in Azure category on for Beginner level | Points: 250 | Views : 6064 red flag
Rating: 5 out of 5  
 4 vote(s)

In this article we will look into how to detect language by using Text Analytics API 2.0.


Text Analytics API is a cloud-based web service supported by Microsoft Cognitive Services that provides advanced natural language processing over raw text and includes three main functions: language detection, key phrase extraction, sentiment analysis

This API does not need any training dataset.In it's present state, the API is able to detect 120 languages.

In this article we will look into how to detect language by using Text Analytics API 2.0.

Let's do the experiment

Step 1

Let us first get the Text Analytics API key(s)

Step 2

Open Visual Studio 2017 and fire a console application

Step 3

From the Nuget package manager console, fire the below

PM > Install-Package Microsoft.Azure.CognitiveServices.Language -Version 1.0.0-preview

Step 4

Let us write the below code

using Microsoft.Azure.CognitiveServices.Language.TextAnalytics;
using Microsoft.Azure.CognitiveServices.Language.TextAnalytics.Models;
using System;
using System.Collections.Generic;
using System.Linq;

namespace textanalytics
    class Program
        static void Main(string[] args)
            //Initialize a new instance of the TextAnalyticsAPI class
            ITextAnalyticsAPI client = new TextAnalyticsAPI();

            //set the endpoint region.
            client.AzureRegion = AzureRegions.Westcentralus;

            //set the subscription key
            client.SubscriptionKey = "YOUR SUBSCRIPTION KEY";

                //The API returns the detected language and a numeric score between 0 and 1.
                     new BatchInput(
                         new List<Input>()
                          new Input("1", "I am a boy"),
                          new Input("2", "je suis un garçon"),
                          new Input("3", "??? ???"),
                          new Input("4","??? ???? ????"),
                          new Input("5", "??????"),
                          new Input("6", "Jeg er en dreng"),
                          new Input("7", "?? ?????"),
                          new Input("8","sono un ragazzo"),
                          new Input("9", "Ich bin ein Junge"),
                          new Input("10", "soy un chico"),
                          new Input("11", "jag är en pojke"),
                          new Input("12", "??????"),
                          new Input("13", "??? ?? ????? ???"),
                          new Input("14", "e?µa? a????")

                         //gets the documents collection

                         //display the document result
                         .ForEach(i =>
                                     Console.WriteLine("" +
                                     "ID: {0} ," +
                                     " Language: {1}, " +
                                     " Iso6391Name : {2}, " +
                                     " Confidence Level : {3}",

First we create a new instance of the TextAnalyticsAPI class

ITextAnalyticsAPI client = new TextAnalyticsAPI();

We then provide the language text in the DetectLanguage API that returns the detected language and the level of confidence which is a value that lies between 0-1.

Step 5

Now let's run the application.

For our experimental sake, we have supplied text in 14 different languages and the Text Analytics API is able to detect all of them with a confidence level of 1.That's amazing!!!.


  1. Text Analytics API
  2. Text Analytics API Version 2.0


In this article we learnt Language Detection using Text Analytics API 2.0 Cognitive Service with examples.Hope this helps. Thanks for reading.

Page copy protected against web site content infringement by Copyscape

About the Author

Full Name: Niladri Biswas (RNA Team)
Member Level: Platinum
Member Status: Member,Microsoft_MVP,MVP
Member Since: 3/17/2015 2:41:06 AM
Country: India
-- Thanks & Regards, RNA Team

Login to vote for this post.

Comments or Responses

Posted by: Rahulsinghdigit on: 8/4/2018 | Points: 25
Thanks a lot for sharing us about this update. Hope you will not get tired on making posts as informative as this.
Posted by: Rajeshsharma on: 8/13/2018 | Points: 25
Great job, I have got interesting points and methods here after reading this hypnosis-down under blog, keep it up.
Posted by: Nadeemogen on: 8/21/2018 | Points: 25
nice topic which you have choose.
second is, the information which you have provided is better then other blog.
so nice work keep it up. And thanks for sharing.
Posted by: Laurielewis042 on: 8/31/2018 | Points: 25
very nice I am impressed
Posted by: Acacia on: 10/6/2018 | Points: 25
Thanks for your sharing, it helped a lot for me.
<a href="">asianfanfics</a>
Posted by: Himanshu-Mishra on: 10/31/2018 | Points: 25
Thanks for this impressive article and more knowledgeable just visit our and get the tutorial to add desktop icons windows 10 operating system in easiest way.
Posted by: Rithu on: 12/11/2018 | Points: 25
I think things like this are really interesting. I absolutely love to find unique places like this. It really looks super creepy though!!

Check out :
Posted by: Kavinilavu on: 12/18/2018 | Points: 25
Great post! I am actually getting ready to across this information, It's very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well."
Posted by: Emmaroy on: 4/20/2019 | Points: 25
Couponing is easy with these top coupon sites. Most have verified coupons you can print that will save you up to 90% on groceries, clothes on Myntra coupons
Posted by: Webclickindia on: 5/1/2019 | Points: 25
Great post! It's very helpful really Thanks for this impressive article
Best website designing company in delhi

Login to post response

Comment using Facebook(Author doesn't get notification)