LoginSignup
5
1

More than 5 years have passed since last update.

3. Amazon AlexaのCustom Slot Typesを設定する

Last updated at Posted at 2017-09-25

連載記事

前後関係があるため順番に読んでもらえると分かりやすくなっています。

1. Amazon AlexaとFire TVでHello Worldを試してみる - Qiita
2. Amazon Alexaで音声から引数を受け取る - Qiita
3. Amazon AlexaのCustom Slot Typesを設定する - Qiita
4. Amazon AlexaからHerokuのRailsにつなぐ - Qiita
5. Amazon Alexaで会話を続ける(セッションを引き継ぐ) - Qiita
6. Amazon Alexa のスキルを日本語化する - Qiita
7. 自作した日本語のAlexa SkillをEcho dotで動かす - Qiita

はじめに

前回はSlotを使って入力音声のテキストを引数としてプログラムに渡しました。
今回は引数の型にあたるSlotを独自のものに置き換えてみます。
Slotについては前回の記事を参考にしてください。

Amazon Alexaで音声から引数を受け取る - Qiita

Custom Slot Typesを定義する

SlotにはAmazonが定義した型が複数準備されていますが、この型を独自に定義することができます。
今回は独自定義のCustom Slot Typesを設定します。まずはいつも通りAlexaの開発者ポータルに行きます。

Amazon開発者ポータル

Interaction ModelのCustom Slot TypesのEnter TypeにJP_FIRST_NAMEと入力します。
これがCustom Slot Typesの型名になります。
その下のEnter Valuesに定義内容を行ごとに入力します。
今回は日本人のよくある名前を値として定義します。

tarou
hanako
tochi

最後に右横の「Add」ボタンを押すとCustom Slotとして追加されます。

Intent SchemaをCustom Slot Typesに変更する

後はIntent SchemaのSlot TypeをCustom Slot Typeで指定した型名に変更します。

{
  "intents": [
    {
      "intent": "HelloWorldIntent",
      "slots": [
        {
          "name": "firstName",
          "type": "JP_FIRST_NAME"
        }
      ]
    }
  ]
}

じつはコレだけでCustom Slot Typeの設定は完了です。
設定後の画面はこんな感じ。

スクリーンショット_2017-09-09_20_23_29.png

疑問

ただ、色々と検証をしていると何故か登録していない名前でも結果が返ってくることがあります。
DefaultのSlotがあって、Custom Slotはそれに追記する形なのか?調べてみたんですがわかりませんでした。
知っている方がいればぜひコメントで教えてください。

結果

僕「Tell hello world hello my name is Tarou」
Alext「Hello world Tarou」

Let's enjoy Alexa.

5
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
1