Skip to content

Instantly share code, notes, and snippets.

@sanjay-kv
Created July 26, 2019 18:33
Show Gist options
  • Save sanjay-kv/b394d4a6aef79bd366635f2e717c0801 to your computer and use it in GitHub Desktop.
Save sanjay-kv/b394d4a6aef79bd366635f2e717c0801 to your computer and use it in GitHub Desktop.
Alexa Hindi Voice app development
const Alexa = require('ask-sdk-core');
const data = [
'अविश्वसनीय चीजें आसानी से की जा सकती हैं यदि हम उन्हें करने के लिए प्रतिबद्ध हैं',
'कुंठा, निराशा और अवसाद का मतलब है कि आप अपने खिलाफ काम कर रहे हैं',
'एक बार जब आपका मन पूर्ण रूप से स्थिर हो जाता है तब आपकी बुद्धि मानवीय सीमाओं को पार कर जाती है',
'आध्यात्मिकता का मतलब है क्रमिक विकास की प्रक्रिया को फ़ास्ट-फॉरवर्ड पे डालना',
'हर चीज को ऐसे देखना जैसी कि वो है, आपको जीवन को सहजता से जीने की शक्ति और क्षमता देता है',
];
const GET_FACT_MESSAGE = "यहाँ आपका fact: ";
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest';
},
handle(handlerInput) {
const speechText ='आपका स्वागत है, आप अच्छे उद्धरण सुनना चाहते हैं?';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const HelloWorldIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
},
handle(handlerInput) {
const speechText = 'Hello World!';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
};
const GetNewFactIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'GetNewFactIntent';
},
handle(handlerInput) {
const factArr = data;
const factIndex = Math.floor(Math.random() * factArr.length);
const randomFact = factArr[factIndex];
const speechOutput = GET_FACT_MESSAGE + randomFact;
const speechText = speechOutput;
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
};
const HelpIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.HelpIntent';
},
handle(handlerInput) {
const speechText = 'आप मुझे नमस्ते कह सकते हैं! मैं आपकी कैसे मदद कर सकता हूँ?';
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
const CancelAndStopIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& (handlerInput.requestEnvelope.request.intent.name === 'AMAZON.CancelIntent'
|| handlerInput.requestEnvelope.request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
const speechText = 'अलविदा!';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
};
const SessionEndedRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
},
handle(handlerInput) {
return handlerInput.responseBuilder.getResponse();
}
};
const IntentReflectorHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest';
},
handle(handlerInput) {
const intentName = handlerInput.requestEnvelope.request.intent.name;
const speechText = `You just triggered ${intentName}`;
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
}
};
const ErrorHandler = {
canHandle() {
return true;
},
handle(handlerInput, error) {
console.log(`~~~~ Error handled: ${error.message}`);
const speechText = `क्षमा करें, मैं समझ नहीं पाया कि आपने क्या कहा। कृपया पुन: प्रयास करें।`;
return handlerInput.responseBuilder
.speak(speechText)
.reprompt(speechText)
.getResponse();
}
};
exports.handler = Alexa.SkillBuilders.custom()
.addRequestHandlers(
LaunchRequestHandler,
HelloWorldIntentHandler,
GetNewFactIntentHandler,
HelpIntentHandler,
CancelAndStopIntentHandler,
SessionEndedRequestHandler,
IntentReflectorHandler)
.addErrorHandlers(
ErrorHandler)
.lambda();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment