一、注冊與環(huán)境搭建

  1. Amazon Developer Console

  2. AWS 賬戶與 IAM 權(quán)限

  3. 安裝 ASK CLI

    npm install -g @ask-cli/ask-cli
    ask configure
  4. 本地開發(fā)依賴


二、創(chuàng)建 “Hello World” Alexa 技能

2.1 新建項目

ask new --skill-name hello-alexa --template hello-world
cd hello-alexa

這將生成包含 models/en-US.jsonlambda/index.js 及部署腳本的項目模版。

2.2 定義 Interaction Model

models/en-US.json 中,你可以看到:

{
  "interactionModel": {
    "languageModel": {
      "invocationName": "hello alexa",
      "intents": [
        {
          "name": "HelloWorldIntent",
          "samples": ["hello", "say hello", "greet me"]
        },
        { "name": "AMAZON.HelpIntent" },
        { "name": "AMAZON.CancelIntent" },
        { "name": "AMAZON.StopIntent" }
      ]
    }
  }
}

2.3 編寫 Lambda 邏輯

lambda/index.js 中使用 ask-sdk-core

const Alexa = require('ask-sdk-core');

const HelloWorldIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'HelloWorldIntent';
  },
  handle(handlerInput) {
    const speechText = 'Hello from your first Alexa skill!';
    return handlerInput.responseBuilder
      .speak(speechText)
      .getResponse();
  }
};

exports.handler = Alexa.SkillBuilders.custom()
  .addRequestHandlers(HelloWorldIntentHandler)
  .lambda();

2.4 部署與測試

ask deploy

三、擴展技能:自定義槽位和多輪對話

3.1 添加槽位(Slots)

創(chuàng)建一個查詢城市天氣的技能,定義 GetWeatherIntent

{
  "name": "GetWeatherIntent",
  "slots": [
    {
      "name": "City",
      "type": "AMAZON.US_CITY"
    }
  ],
  "samples": ["what's the weather in {City}", "weather in {City}"]
}

在 Lambda 中讀取槽位值:

const GetWeatherIntentHandler = {
  canHandle(handlerInput) {
    return handlerInput.requestEnvelope.request.type === 'IntentRequest'
      && handlerInput.requestEnvelope.request.intent.name === 'GetWeatherIntent';
  },
  async handle(handlerInput) {
    const city = handlerInput.requestEnvelope.request.intent.slots.City.value;
    const weather = await fetchWeather(city); // 調(diào)用外部 API
    return handlerInput.responseBuilder
      .speak(`The weather in ${city} is ${weather}.`)
      .getResponse();
  }
};

3.2 實現(xiàn)多輪對話

為應對缺少槽位的情況,可以啟用 Dialog Management:

  1. models/en-US.json 中為 GetWeatherIntent 添加 dialog 配置。
  2. 使用 Alexa.SkillBuilders.custom().addRequestHandlers() 中的 Delegate 指令進行對話委派。
if (handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED') {
  return handlerInput.responseBuilder
    .addDelegateDirective()
    .getResponse();
}

四、使用 Alexa Simulator 與 CloudWatch 調(diào)試

4.1 Alexa Simulator

4.2 CloudWatch 日志


五、部署生產(chǎn):版本管理與發(fā)布

  1. ASK CLI Profiles

    ask deploy --profile prod
  2. 技能發(fā)布


六、進階方向:智能家居與多模態(tài)交互

6.1 Smart Home Skills

6.2 多模態(tài)界面(APL)

在支持屏幕的 Echo 設備上,使用 APL 展示圖文、按鈕等:

handlerInput.responseBuilder.addDirective({
  type: 'Alexa.Presentation.APL.RenderDocument',
  document: require('./documents/template.json'),
  datasources: { ... }
});

七、常見問題與最佳實踐


八、資源與學習路徑


九、結(jié)語

從注冊賬號、環(huán)境配置,到 Interaction Model 設計、Node.js Lambda 編寫,再到測試調(diào)優(yōu)與技能上線,本文覆蓋了“零基礎入門 Alexa API 開發(fā)”的完整路徑。依托 ASK CLI、Alexa Simulator、CloudWatch 日志等工具,你可以快速迭代語音技能,逐步擴展至智能家居、多模態(tài)交互與第三方 API 集成。希望你通過本文深度掌握 Alexa 技能開發(fā),并在語音交互的浪潮中搶占先機!

上一篇:

深入解析 DeepSeek API 密鑰:獲取、使用與最佳實踐
最后一篇
#你可能也喜歡這些API文章!

我們有何不同?

API服務商零注冊

多API并行試用

數(shù)據(jù)驅(qū)動選型,提升決策效率

查看全部API→
??

熱門場景實測,選對API

#AI文本生成大模型API

對比大模型API的內(nèi)容創(chuàng)意新穎性、情感共鳴力、商業(yè)轉(zhuǎn)化潛力

25個渠道
一鍵對比試用API 限時免費

#AI深度推理大模型API

對比大模型API的邏輯推理準確性、分析深度、可視化建議合理性

10個渠道
一鍵對比試用API 限時免費