Today we announced that developers can now use the Alexa Skills Kit (ASK) to build skills for Hindi speaking customers in India using the new Hindi (hi-IN) language model. This is a detailed walkthrough for building your first skill in Hindi. To add the Hindi language model to your existing skill, read this detailed guide.
In this tutorial, you will learn:
6. Keep the default Custom model selected, and scroll the page down. Choose Alexa-Hosted for the method to host your skill's backend resources. If you would prefer to manage the backend resources in your own AWS account or HTTPS endpoint, choose the Provision your own option. Check out this guide for a walkthrough on how to manage your backend with an AWS account.
Every skill has a front end and a back end. The front end is where you map utterances (what the user says) into an intent (the desired action). You must decide how to handle the user's intent in the backend. Let’s build the front end of the skill.
1. On the left-hand navigation panel, select the Invocation tab under Interaction Model. In the text field provided, the invocation name by default will be नमस्ते दुनिया. Let’s leave it as is.
2. By default, the skill has a HelloWorldIntent. Let’s remove all existing utterances and add Hindi utterances that indicate a sort of greeting. Here are few:
नमस्ते दुनिया
नमस्ते
नमस्ते friend
hello
You will note that these utterances contain a mix of Hindi and English. A rule of thumb to follow is to use Devanagari script for Hindi words and Latin script for foreign words.
3. Once you’ve added a sufficient number of utterances, save and build your model. We will now build the back end for your skill.
The first thing a user will want to do with the skill is open it. The intent of opening the skill is built into the experience, so you don't need to define this intent in your front end. However, you need to respond to the HelloWorldIntent intent in your backend. In this step, you will update your backend code to greet the user when they open the skill.
1. Open the नमस्ते दुनिया skill in the Alexa developer console. Click the Code tab. The code editor opens the index.js file.
2. You will use the ASK SDK for Node.js module. To define how your skill responds to a JSON request, you will define a handler for each intent
There are two pieces to a handler:
canHandle() function
handle() function
The canHandle() function is where you define what requests the handler responds to.
The handle() function returns a response to the user.
If your skill receives a request, the canHandle() function within each handler determines whether or not that handler can service the request. In this case, the user wants to launch the skill, which is a LaunchRequest. Therefore, the canHandle() function within the LaunchRequestHandler will let the SDK know it can fulfill the request.
3. This speechText variable in the LaunchRequestHandler() method contains the string of words the skill should say back to the user when they launch the skill. Let’s modify the speechText variable to hear Alexa speak in Hindi.
const speechText = “नमस्ते, आप hello या help कह सकते हो. आप क्या करना चाहेंगे?”
4. Look for handlerInput.responseBuilder. This piece of the SDK will help build the response to the user. On the next line, look for .speak(speechText). Note the speechText variable, which you defined earlier. Calling the .speak() function tells responseBuilder to speak the value of speechText to the user.
5. If you look at the code, you will notice the HelloWorldIntentHandler. This method handles any request from the HelloWorldIntent. Earlier we had defined few utterances for this intent in our interaction model. Let’s modify the speechText variable in the HelloWorldIntentHandler() to reply to the user when the user greets the skill.
const speechText = “नमस्ते दोस्त”
That’s it. Click Save and then Deploy. Your skill will take a few moments to deploy
1. Access the Alexa Simulator, by selecting the Test tab from the top navigation menu. Toggle the dropdown from Off to Development to enable Skill Testing
2. To test your skill, Type the invocation name of your skill followed by a launch phrase. For example, नमस्ते दुनिया खोलो. You can also say Open नमस्ते दुनिया. If all goes well, you will hear the response defined in your LaunchRequestHandler.
3. Test the skill by saying नमस्ते or any of the other utterances we had defined earlier.
That’s it! You have just built your first Hindi skill.
Since your users can reply in a mix of English and Hindi, there are few guidelines and best practices that you should follow while building a Hindi skill. Read this document to find out more.
Alongside our Technical Evangelist (Sohan Maheshwar) and Solutions Architect (Karthik Ragubathy) you will learn how to reach new Hindi speaking customers by building new Hindi skills and updating your existing skill to the Hindi model.