【发布时间】:2017-12-01 15:20:33
【问题描述】:
我正在使用适用于 NodeJS 的 Alexa-SDK,但在使用 AudioPlayer 及其控件时遇到了问题。
问题:
当我使用以下代码 sn-p 启动音频流时,它开始播放(按预期),但没有机会使用内置的“AMAZON.StopIntent”或任何其他可用的意图再次停止播放.
Alexa 回答如下:“在您的服务中处理请求时发生错误。”并一直播放直到曲目播放到最后。
this.response.audioPlayerPlay(behavior, url, token, expectedPreviousToken, offsetInMilliseconds)
this.emit(':responseReady');
这里是我的处理程序,以便更好地了解。我取自skill-sample-nodejs-audio-player的结构:
var stateHandlers = {
startModeIntentHandlers : Alexa.CreateStateHandler(constants.states.START_MODE, {
'LaunchRequest': function() {
this.handler.state = constants.states.PLAY_OCCASION_MODE;
this.emit(':ask', 'Welcome, say yes to start the playback.','Say yes to start the playback');
},
'AMAZON.StopIntent': function() {
this.response.audioPlayerStop();
this.emit(':tell', 'See you next Time!');
},
'AMAZON.CancelIntent': function() {
this.emit(':tell', 'See you next Time!');
},
'SessionEndedRequest': function () {
this.emit(':tell', 'See you next Time!');
}
}),
playOccasionModeIntentHandlers : Alexa.CreateStateHandler(constants.states.PLAY_OCCASION_MODE, {
'LaunchRequest': function () {
this.emit('LaunchRequest'); // Uses the handler in newSessionHandlers
},
'AMAZON.YesIntent': function() {
this.handler.state = constants.states.PLAY_OCCASION_MODE;
this.response.speak('Lets go. Here comes your Podcast.');
this.response.audioPlayerPlay('REPLACE_ALL', 'https://feeds.soundcloud.com/stream/274166909-amazon-web-services-306355661-aws-podcast-episode-139.mp3', 'earlybird', null, 0);
this.emit(':responseReady');
},
'AMAZON.NoIntent': function() {
this.emit(':tell', 'See you next Time!');
},
'AMAZON.StopIntent': function() {
this.response.audioPlayerStop();
this.response.speak('See you next Time!');
this.emit(':responseReady');
},
'AMAZON.CancelIntent': function() {
this.emit(':tell', 'See you next Time!');
},
'SessionEndedRequest': function () {
this.emit(':tell', 'See you next Time!');
},
'Unhandled': function() {
this.emit(':tell', 'See you next Time!');
}
}),
};
编辑:
如果我向START_MODE 状态添加一个“未处理”函数,Alexa 将始终以这个函数回答并完全忽略 StopIntent。
这是第一个解决方法,但是当涉及到更高级的功能(例如播放下一首歌曲或暂停播放)时,问题又回来了。
'Unhandled': function() {
this.response.audioPlayerStop();
this.response.speak('Unhandled!');
this.emit(':responseReady');
}
EDIT2:
似乎找到了解决方案。我还没有添加AMAZON.PauseIntent,它也接受“Alexa,停止”命令。通过添加它,它现在似乎或多或少地工作。
'AMAZON.PauseIntent' : function () {
this.response.audioPlayerStop();
this.response.speak('Paused. See you next time!');
this.emit(':responseReady');
},
【问题讨论】:
-
答案属于答案,而不是问题。自我回答一个问题是完全可以的,正确的方法:)
标签: node.js audio playback alexa alexa-skills-kit