【发布时间】:2016-09-22 20:51:00
【问题描述】:
大家好,我在尝试实现音频播放时遇到了困难。这是docs
所以我真正想做的事情看起来很简单,但结果却很混乱。
我希望能够说出命令。 Alexa 将响应一点 outputSpeech,然后继续播放我将提供的小型音轨 mp3。我不介意在本地上传它(当我压缩文件并将它们导入 lamda 函数时)或使用 S3 Buckets SDK 流式传输 mp3 文件。哪个对你们来说更容易。
这是我目前得到的。
通过下面的代码,我可以让 Alexa 响应语音并输出语音。
我只是使用 IntentRequest 为你们减少代码。
- 我会说“Alexa 打开 myApp 并播放我的音乐”
- “播放我的音乐”是我在 alexa 开发者控制台中设置技能时要列出的命令
exports.handler = (event, context, callback) => {
try {
if (event.request.type === 'IntentRequest') {
onIntent(event.request,
event.session,
(sessionAttributes, speechletResponse) => {
callback(null, buildResponse(sessionAttributes, speechletResponse));
});
}
} catch (err) {
callback(err);
}
};
Intent 请求通过时将调用的函数
- 我的意图名称将是 PlayMyMusic
function onIntent(intentRequest, session, callback) {
console.log(`onIntent requestId=${intentRequest.requestId}, sessionId=${session.sessionId}`);
const intent = intentRequest.intent;
const intentName = intentRequest.intent.name;
if (intentName === 'PlayMyMusic') {
PlayMyMusic(intent, session, callback);
} else if (intentName === 'AMAZON.StopIntent' || intentName === 'AMAZON.CancelIntent') {
handleSessionEndRequest(callback);
} else {
throw new Error('Invalid intent');
}
}
这是输出消息
function PlayMyMusic(intent, session, callback) {
const repromptText = null;
const sessionAttributes = {};
let shouldEndSession = true;
let speechOutput = '';
speechOutput = `I'm Alexa and I will output speech in this area. After I'm done talking I will play an audio track`;
callback(sessionAttributes,
buildSpeechletResponse(intent.name, speechOutput, repromptText, shouldEndSession));
}
这是我的简单 Intent Schema
{
"intents": [
{
"intent": "PlayMyMusic"
},
{
"intent": "AMAZON.HelpIntent"
}
]
}
示例话语
PlayMyMusic play my music
目前一切正常,亚马逊可以回复我并结束会话。
如何让亚马逊回复我,然后播放一些音频?这些文档有点不适合我。
【问题讨论】:
-
你得到答案了吗?
标签: javascript audio alexa-skills-kit amazon-echo