Alexa,做笔记并通过邮件发送
Alexa, taking notes and send them via mail
我想学习编写 Alexa Skills,所以我觉得一个 Skill,可以记录用户的语音并写下来,稍后通过邮件发送给他,会很酷。
我设法让用户启动了技能,但我不知道如何保存用户的"notes"。我在 google 上没有找到任何东西,所以我试着在这里问一下。
到今天为止,这个用例不能用技能开发。没有 API 只允许捕获原始用户或语音识别输入。一项技能接收语音识别 和 自然语言理解的结果,表示为 Intent 和一组实体。
我设法意识到了我的问题。
这是我的解决方案:
Intent(表述为德语,但槽 {NoteInput} 很重要)
{
"interactionModel": {
"languageModel": {
"invocationName": "mail notes",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "noteIntent",
"slots": [
{
"name": "NoteInput",
"type": "AMAZON.SearchQuery",
"samples": [
"notiere {NoteInput}",
"{NoteInput}"
]
}
],
"samples": [
"und schreibe auf {NoteInput}",
"und notiere {NoteInput}",
"notiere {NoteInput}",
"sende mir folgendes",
"und schreib auf",
"und notiere",
"notiere",
"und schreib mit",
"schreib mit",
"schreib auf"
]
}
]
},
"dialog": {
"intents": [
{
"name": "noteIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "NoteInput",
"type": "AMAZON.SearchQuery",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.61384016725.485372519591"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Slot.61384016725.485372519591",
"variations": [
{
"type": "PlainText",
"value": "Sehr wohl, ich trage zu protokoll"
},
{
"type": "PlainText",
"value": "Gerne, ich notiere"
},
{
"type": "PlainText",
"value": "Sehr wohl, ich notiere"
},
{
"type": "PlainText",
"value": "Gerne, ich schreibe mit"
}
]
}
}
}
如您所见,插槽 {NoteInput} 的插槽类型为 AMAZON.SearchQuery。这将导致 Alexa 简单地传输 Speech-to-Text。
Lambda 函数中的处理程序如下所示:
const inProgressNoteIntentHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'noteIntent'
&& request.dialogState !== 'COMPLETED' ;
},handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();
}
};
const completeNoteIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'noteIntent';
},handle(handlerInput) {
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
console.log("Folgende Slots im noteIntent " + slotValues.NoteInput.synonym);
noteArr.push(slotValues.NoteInput.synonym);
console.log(noteArr.toString());
return handlerInput.responseBuilder
.speak("Ok, ich habe " +slotValues.NoteInput.synonym+ " notiert.")
.getResponse();
},
};
您需要此函数来获取插槽的值:
function getSlotValue(slot){
let value = slot.value;
let resolution = (slot.resolutions && slot.resolutions.resolutionsPerAuthority && slot.resolutions.resolutionsPerAuthority.length > 0) ? slot.resolutions.resolutionsPerAuthority[0] : null;
if(resolution && resolution.status.code == 'ER_SUCCESS_MATCH'){
let resolutionValue = resolution.values[0].value;
value = resolutionValue.name;
}
return value;
}
我想学习编写 Alexa Skills,所以我觉得一个 Skill,可以记录用户的语音并写下来,稍后通过邮件发送给他,会很酷。
我设法让用户启动了技能,但我不知道如何保存用户的"notes"。我在 google 上没有找到任何东西,所以我试着在这里问一下。
到今天为止,这个用例不能用技能开发。没有 API 只允许捕获原始用户或语音识别输入。一项技能接收语音识别 和 自然语言理解的结果,表示为 Intent 和一组实体。
我设法意识到了我的问题。 这是我的解决方案: Intent(表述为德语,但槽 {NoteInput} 很重要)
{
"interactionModel": {
"languageModel": {
"invocationName": "mail notes",
"intents": [
{
"name": "AMAZON.CancelIntent",
"samples": []
},
{
"name": "AMAZON.HelpIntent",
"samples": []
},
{
"name": "AMAZON.StopIntent",
"samples": []
},
{
"name": "noteIntent",
"slots": [
{
"name": "NoteInput",
"type": "AMAZON.SearchQuery",
"samples": [
"notiere {NoteInput}",
"{NoteInput}"
]
}
],
"samples": [
"und schreibe auf {NoteInput}",
"und notiere {NoteInput}",
"notiere {NoteInput}",
"sende mir folgendes",
"und schreib auf",
"und notiere",
"notiere",
"und schreib mit",
"schreib mit",
"schreib auf"
]
}
]
},
"dialog": {
"intents": [
{
"name": "noteIntent",
"confirmationRequired": false,
"prompts": {},
"slots": [
{
"name": "NoteInput",
"type": "AMAZON.SearchQuery",
"confirmationRequired": false,
"elicitationRequired": true,
"prompts": {
"elicitation": "Elicit.Slot.61384016725.485372519591"
}
}
]
}
]
},
"prompts": [
{
"id": "Elicit.Slot.61384016725.485372519591",
"variations": [
{
"type": "PlainText",
"value": "Sehr wohl, ich trage zu protokoll"
},
{
"type": "PlainText",
"value": "Gerne, ich notiere"
},
{
"type": "PlainText",
"value": "Sehr wohl, ich notiere"
},
{
"type": "PlainText",
"value": "Gerne, ich schreibe mit"
}
]
}
}
}
如您所见,插槽 {NoteInput} 的插槽类型为 AMAZON.SearchQuery。这将导致 Alexa 简单地传输 Speech-to-Text。
Lambda 函数中的处理程序如下所示:
const inProgressNoteIntentHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'noteIntent'
&& request.dialogState !== 'COMPLETED' ;
},handle(handlerInput) {
const currentIntent = handlerInput.requestEnvelope.request.intent;
return handlerInput.responseBuilder
.addDelegateDirective(currentIntent)
.getResponse();
}
};
const completeNoteIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'noteIntent';
},handle(handlerInput) {
const filledSlots = handlerInput.requestEnvelope.request.intent.slots;
const slotValues = getSlotValues(filledSlots);
console.log("Folgende Slots im noteIntent " + slotValues.NoteInput.synonym);
noteArr.push(slotValues.NoteInput.synonym);
console.log(noteArr.toString());
return handlerInput.responseBuilder
.speak("Ok, ich habe " +slotValues.NoteInput.synonym+ " notiert.")
.getResponse();
},
};
您需要此函数来获取插槽的值:
function getSlotValue(slot){
let value = slot.value;
let resolution = (slot.resolutions && slot.resolutions.resolutionsPerAuthority && slot.resolutions.resolutionsPerAuthority.length > 0) ? slot.resolutions.resolutionsPerAuthority[0] : null;
if(resolution && resolution.status.code == 'ER_SUCCESS_MATCH'){
let resolutionValue = resolution.values[0].value;
value = resolutionValue.name;
}
return value;
}