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:
- How to create the language model for a Hindi skill
- How to create your skill’s backend so your skill delivers the right content to your customers
Create a skill in 5 minutes
- Go to the Amazon Developer Portal. In the top-right corner of the screen, click the "Sign In" button (If you don't already have an account, you will be able to create a new one for free.)
- Once you have signed in, move your mouse over the ‘Your Alexa Consoles’ text at the top of the screen and Select the Skills Link.
- Click the ‘Create Skill’ button
- To type in Hindi, you can choose to use the built-in keyboard on your OS or a transliteration tool of your choice.
- We are going to create a simple Hello World skill in Hindi. Give your new skill a Name, such as नमस्ते दुनिया. Choose the Default Language as Hindi (IN).
- 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.
- Scroll back up and select the Create Skill button at the top right. It will take a minute to create your Alexa-hosted skill, then you will be taken to the Build tab of the console.
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.
Build the Interaction Model for your skill
- 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.
- 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:
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.
- Once you’ve added a sufficient number of utterances, save and build your model. We will now build the back end for your skill.
Build the backend of the 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.
- Open the नमस्ते दुनिया skill in the Alexa developer console. Click the Code tab. The code editor opens the index.js file.
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:
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.
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 कह सकते हो. आप क्या करना चाहेंगे?”
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.
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.
Test the Skill in the Simulator
- 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
- 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.
- 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.
Sign up for our first webinar on building Hindi skills on July 24th at 4pm IST. Register here.
Source: Alexa Developer Blog