発話内容をAlexaにおうむ返しさせるサンプル。Alexaは任意の発話を受けるスロットタイプが無いようだが、適当なスロットタイプでいけた。
インテントの設定
インテント名は適当にCopyIntentとし、スロットタイプはAMAZON.Colorを指定。
AMAZON.Colorが任意の文字列を受けられるという情報は、この書籍を参考にした。
おもしろまじめなAIスピーカーアプリをつくろう -Google Home(アシスタント)&Amazon Echo(Alexa)音声アシスタント開発
https://www.shuwasystem.co.jp/products/7980html/5273.html
Lambda関数
CopyIntentHandlerメソッドで、 スロットのmessageを取り出す。
const CopyIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'CopyIntent';
},
handle(handlerInput) {
let value = handlerInput.requestEnvelope.request.intent.slots.message.value;
const speechText = value + 'って言いましたね!';
return handlerInput.responseBuilder
.speak(speechText)
.getResponse();
},
};
とりあえず、これでうまくいった。