大家好,所以我很难尝试实现音频播放。这是docs
所以我真正想要做的事情看起来很简单,但在一切都被假设出现的时候,它变得非常混乱。
我希望能够说出一个命令。 Alexa会响应一点输出声音,然后继续播放我将提供的小型音轨mp3。我不介意在本地上传它(当我压缩文件并将它们导入lamda函数时)或使用S3 Buckets SDK来传输mp3文件。这对你们来说更容易。
这是我到目前为止所得到的。
通过以下代码,我可以让Alexa回应语音并输出语音。
我只使用IntentRequest为您减少代码。
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请求通过时调用
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));
}
这是我简单的意图模式
{
"intents": [
{
"intent": "PlayMyMusic"
},
{
"intent": "AMAZON.HelpIntent"
}
]
}
示例话语
PlayMyMusic play my music
现在一切正常,亚马逊可以回复并结束会话。
我怎样才能让亚马逊回应我,然后播放一些音频?这些文档对我不起作用。