我正在使用 NodeJS 的 Alexa-SDK,并在 AudioPlayer 及其控件方面遇到了麻烦。
问题:
当我使用以下代码片段启动音频流时,它开始播放(按预期),但无法使用内置的“AMAZON.StopIntent”或任何其他可用的 intent 再次停止播放。
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');
}
编辑2:
似乎找到了解决方案。我还没有添加 AMAZON.PauseIntent ,它也接受“Alexa,停止”命令。通过添加它,现在似乎或多或少可以工作。
'AMAZON.PauseIntent' : function () {
this.response.audioPlayerStop();
this.response.speak('Paused. See you next time!');
this.emit(':responseReady');
},
最佳答案
您应该设置 this.handler.state='_PLAY_MODE',然后它将应用 playmodeIntentHandler。
关于node.js - Alexa 在播放时不接受音频命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44799456/