共计 1782 个字符,预计需要花费 5 分钟才能阅读完成。
什么是 Skill?
Skill(或称为 Action 在 Google 平台上)是为语音助手(如 Alexa 或 Google Assistant)开发的应用程序。它们允许用户通过语音命令与你的服务交互,就像在手机上使用 App 一样。主流平台有两种主要架构模式:

- Alexa Skill:基于交互模型(Interaction Model)和 Lambda 函数(或自定义 Web 服务)
- Google Action:使用 Dialogflow 处理自然语言,通过 Webhook 实现业务逻辑
开发准备
环境搭建
- 账号注册:
- Alexa 开发者账号:developer.amazon.com
-
Google Actions 账号:console.actions.google.com
-
工具安装:
- Node.js(推荐 LTS 版本)
- ASK CLI(Alexa 开发工具):
npm install -g ask-cli -
Google Actions CLI:
npm install -g @assistant/gactions -
编辑器选择:
- VS Code(推荐)或任何你熟悉的代码编辑器
实战开发
设计交互模型
以天气查询 Skill 为例:
- 意图(Intents):
- GetWeatherIntent:查询天气
-
HelpIntent:获取帮助
-
话语样本(Utterances):
- “ 今天天气怎么样 ”
- “ 北京明天会下雨吗 ”
代码实现(Node.js 示例)
// Alexa Skill 示例
const Alexa = require('ask-sdk-core');
const GetWeatherHandler = {canHandle(handlerInput) {return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
&& Alexa.getIntentName(handlerInput.requestEnvelope) === 'GetWeatherIntent';
},
async handle(handlerInput) {
const city = handlerInput.requestEnvelope.request.intent.slots.city.value;
// 这里调用天气 API 获取数据
const weatherData = await getWeatherFromAPI(city);
const speakOutput = `${city}今天的天气是 ${weatherData.condition},温度 ${weatherData.temperature}度 `;
return handlerInput.responseBuilder
.speak(speakOutput)
.getResponse();}
};
测试与部署
本地测试
- Alexa 测试:
- 使用 ASK CLI:
ask dialog --locale zh-CN -
或使用开发者控制台的测试工具
-
Google 测试:
- Actions 模拟器:https://console.actions.google.com
发布流程
- 完成所有测试
- 提交审核(Alexa 约 1 - 3 天,Google 约 1 - 7 天)
- 审核通过后 Skill 将上线
避坑指南
- 错误 1:未处理所有必填字段
-
解决方案:确保所有需要的槽位 (slots) 都设置了确认或提供了默认值
-
错误 2:响应超时
-
解决方案:Lambda 函数超时时间设置为 3 秒以内,复杂操作使用延迟响应
-
错误 3:忽略多轮对话
- 解决方案:设计对话时考虑用户可能的中断和继续场景
进阶建议
- 性能优化:
- 使用缓存减少 API 调用
-
预加载常用数据
-
用户体验:
- 添加个性化响应
- 支持语音中断
- 提供可视化卡片(Alexa)或富媒体响应(Google)
练习与资源
实践建议
- 从简单 Skill 开始(如查询时间、天气预报)
- 逐步添加复杂功能(多轮对话、账户关联)
学习资源
- Alexa 官方文档:https://developer.amazon.com/alexa
- Google Actions 文档:https://developers.google.com/assistant
- 语音设计指南:https://developer.amazon.com/designing-for-voice
通过这篇指南,你应该已经掌握了 Skill 开发的基本流程。记住,语音交互设计与传统应用不同,需要更多考虑自然语言场景。多测试、多迭代是开发优秀 Skill 的关键。
正文完
发表至: 技术开发
近一天内
