
模型壓縮四劍客:量化、剪枝、蒸餾、二值化
Amazon Developer Console
AWS 賬戶與 IAM 權(quán)限
AWSLambdaFullAccess
、CloudWatchLogsFullAccess
權(quán)限。安裝 ASK CLI
npm install -g @ask-cli/ask-cli
ask configure
ask configure
會引導(dǎo)你完成與 Amazon Developer 和 AWS IAM 的授權(quán)關(guān)聯(lián)。本地開發(fā)依賴
ask init
或 ask new
創(chuàng)建項目結(jié)構(gòu)。ask new --skill-name hello-alexa --template hello-world
cd hello-alexa
這將生成包含 models/en-US.json
、lambda/index.js
及部署腳本的項目模版。
在 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" }
]
}
}
}
HelloWorldIntent
與內(nèi)置意圖。在 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();
responseBuilder.speak()
用于設(shè)置語音回復(fù)。ask deploy
創(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();
}
};
handlerInput.requestEnvelope.request.intent.slots.City.value
獲取用戶提供的城市名稱。為應(yīng)對缺少槽位的情況,可以啟用 Dialog Management:
models/en-US.json
中為 GetWeatherIntent
添加 dialog
配置。Alexa.SkillBuilders.custom().addRequestHandlers()
中的 Delegate
指令進(jìn)行對話委派。if (handlerInput.requestEnvelope.request.dialogState !== 'COMPLETED') {
return handlerInput.responseBuilder
.addDelegateDirective()
.getResponse();
}
handlerInput
內(nèi)容,驗證意圖命中與參數(shù)傳遞。ASK CLI Profiles
ask deploy --profile prod
dev
、prod
環(huán)境。技能發(fā)布
在支持屏幕的 Echo 設(shè)備上,使用 APL 展示圖文、按鈕等:
handlerInput.responseBuilder.addDirective({
type: 'Alexa.Presentation.APL.RenderDocument',
document: require('./documents/template.json'),
datasources: { ... }
});
entity resolution
精準(zhǔn)匹配槽位值。視頻教程:Zero to Hero 系列,涵蓋從基礎(chǔ)到高級的 Alexa Skills 開發(fā)。
官方文檔:
開源示例:GitHub 上搜索 “alexa-skills-kit” 獲取社區(qū)實踐案例。
從注冊賬號、環(huán)境配置,到 Interaction Model 設(shè)計、Node.js Lambda 編寫,再到測試調(diào)優(yōu)與技能上線,本文覆蓋了“零基礎(chǔ)入門 Alexa API 開發(fā)”的完整路徑。依托 ASK CLI、Alexa Simulator、CloudWatch 日志等工具,你可以快速迭代語音技能,逐步擴(kuò)展至智能家居、多模態(tài)交互與第三方 API 集成。希望你通過本文深度掌握 Alexa 技能開發(fā),并在語音交互的浪潮中搶占先機(jī)!