我正在尝试实现Alexa的播放功能,以播放从API调用中获得的mp3文件。我很好地得到了数据,而且speak指令确实包含了来自API响应的数据,所以我知道调用起作用了,但是文件本身永远不会播放。
我正在使用物理回声设备进行测试。
Cloudwatch日志不是特别有帮助(有没有更好的地方可以让我看到整个堆栈跟踪?),但我确实看到了一个错误:
Unable to find a suitable request handler.随后结束与undefined的会话。
下面是我的实现代码:
接口调用:
const getEpisode = uri => new Promise(
(resolve, reject) => {
httpRequest({
method: 'GET',
uri,
json: true,
headers: {
'X-API-KEY': key,
},
}).then(data => {
console.log(data);
return resolve(data);
})
.catch(err => reject(new Error(err)));
}
);PlayIntent:
const PlayIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest' ||
(handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'PlayIntent') ||
(handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'AMAZON.ResumeIntent');
},
async handle(handlerInput) {
const uri = `${endpoint}/most_recent/amazon`;
console.log(uri);
const data = await getEpisode(uri);
console.log("before setting response");
return handlerInput.responseBuilder
.speak(`Playing episode ${data.episode_title}`)
.addAudioPlayerPlayDirective('REPLACE_ALL', data.episode_url, data.episode_title, 0, null, null)
.withShouldEndSession(true)
.getResponse()
},
};你知道我哪里错了吗?
发布于 2018-12-08 02:17:41
addAudioPlayerPlayDirective有5个参数:
playBehavior - 'REPLACE_ALL'
url - data.episode_url
enqueueToken - data.episode_title
offsetInMilliseconds - `0`
expectedPreviousToken - `null`.addAudioPlayerPlayDirective('REPLACE_ALL',data.episode_url,data.episode_title,0,null,null)
正如您所看到的,您有一个额外的参数null被传递。去掉它。
https://stackoverflow.com/questions/53657786
复制相似问题