如何为 Alexa Skill 扩展自定义插槽类型?

How to expand custom slot types for Alexa Skill?

我想问一个航班号。航班号由一个短代码(如 EZY、AFR、DLH 或 CCA)和一个 3 到 5 位数字的航班号组成。因为我有这些有限的代码集和大量的潜在数字,我不知道如何定义我的插槽类型。

我考虑过将其拆分为自定义插槽类型 CODE 和集成的 AMAZON.NUMBERS 类型。这样我 运行 就陷入了我的模型中的问题,因为它们都需要实现我的意图,我将不得不两次询问插槽。

只输入所有数字的选项似乎是非常糟糕的做法。我将如何连接插槽类型?

提前致谢。

您可以而且应该使用一个自定义 SlotType。

Alexa Custom SlotTypes:

A custom slot type defines a list of representative values for the slot. Custom slot types are used for lists of items that are not covered by Amazon's built-in set of types.
...
Slot values are sent to your skill in written format. For example, both "fire h. d. 7" and "fire h. d. seven" would be sent to your skill as "Fire HD7". For better recognition, acronyms and other phrases involving spoken letters should either be all caps ("HD") or separated by periods and a space ("h. d. ").

知道您在自定义 SlotTypes 中定义的值不会限制识别用户输入以填充插槽。因此,您无需编写字母数字航班代码的所有可能组合。只需给它大量的样本,Alexa 就会根据但不限于 这些样本值来学习模式并识别语言

这里有一些关于如何在 SlotType 中写入值的建议,以便 Alexa 输出您想要的格式:Custom SlotType Values

创建自定义 FLIGHT_NUMBER 插槽并提供各种样本值。

When you create a custom slot type, a key concept to understand is that this is training data for Alexa’s NLP (natural language processing). The values you provide are NOT a strict enum or array that limit what the user can say. This has two implications

1) words and phrases not in your slot values will be passed to you,

2) your code needs to perform any validation you require if what’s said is unknown.

插槽值中的缩写和数字

当您处理 EZY、AFR 或 DLH 等缩写并后跟数字时,您必须像这样给出示例槽值。 (尝试提供更多变化)

e. z. y. two four seven nine three four
a. f. r. one two three four one two 
d. l. h. two three eight zero eight zero

并始终在后端验证您的插槽值。

在测试模拟器中测试它时使用像

这样的话语

flight number a. f. r. one two three four one two

您将获得插槽的值 AFR238080。 Alexa 生成的示例请求如下:

"intent": {
            "name": "FlightNumberIntent",
            "confirmationStatus": "NONE",
            "slots": {
                "flightNumber": {
                    "name": "flightNumber",
                    "value": "AFR238080",

...