今の発話がどのインテントであるかという判断は、アレクサ側でやってくれる。
こっちは、インテントとサンプル発話を用意するだけでいい。
アレクサ側で音声認識をし、それを文字に起こし、どのインテントに当てはまりそうかをサンプル発話を参考に判定する。
例:
HungryIntentというインテントを用意。
サンプル発話は「お腹がすいた」
アレクサのデベロッパーコンソールのテストでスキルを起動し「お腹がすいた」と発話すると、以下の情報がバックエンドに送られる。↓
「IntentRequest
であるかつ、intentの名前はHungryIntent
である」という情報。
"request": {
"type": "IntentRequest",
"requestId": "リクエストのID",
"timestamp": "タイムスタンプ",
"locale": "ja-JP",
"intent": {
"name": "HungryIntent",
"confirmationStatus": "NONE"
},
"dialogState": "STARTED"
}
バックエンドは、インテントの名前を受け取り、HungryIntentHandlerの処理を行う。
class HungryIntentHandler(AbstractRequestHandler):
def can_handle(self, handler_input):
return is_intent_name("HungryIntent")(handler_input)
def handle(self, handler_input):
handler_input.response_builder.speak('わかる').ask('わかるよ')
return handler_input.response_builder.response
この場合、アレクサが「わかる」と言ってくれる。