简体   繁体   English

Alexa,做笔记并通过邮件发送

[英]Alexa, taking notes and send them via mail

I'd like to learn to write Alexa Skills, so I thought a Skill, that records the users speech and writes it down, to send it to him via mail later, would be pretty cool. 我想学习写Alexa技能,所以我认为记录用户语音并将其记录下来,然后通过邮件发送给他的技能非常不错。

I managed to let the user Start the Skill but I have no idea how to save the "notes" of the user. 我设法让用户开始使用此技能,但是我不知道如何保存用户的“笔记”。 I havent found anything on google, so I tried to ask here. 我还没有在Google上找到任何东西,所以我试图在这里问。

As of today, this use case can not developed with a Skill. 到今天为止,该用例尚无法通过技能开发。 There is no API to allow to capture raw user or speech recognition input only. 没有API仅允许捕获原始用户或语音识别输入。 A skill receives the result of speech recognition and natural language understanding, expressed as an Intent and a set of entities. 技能接收语音识别自然语言理解的结果,表示为意图和一组实体。

I managed to realize my problem. 我设法意识到了我的问题。 Here is my solution: Intent (Utterances are in German, but the Slot {NoteInput} is important) 这是我的解决方案:目的(话语是德语,但是槽{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"
                }
            ]
        }
}

} }

As you can see the Slot {NoteInput} got AMAZON.SearchQuery as Slottype. 如您所见,插槽{NoteInput}获得了AMAZON.SearchQuery作为插槽类型。 This will cause Alexa to simply transfer Speech-to-Text. 这将导致Alexa简单地将语音转换为文本。

The Handler in the Lambda-Function looks like this: 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();

  },


};

You'll need this function to get the Value of the Slot: 您将需要以下函数来获取广告位的值:

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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM