几天前,我已经通过Alexa Developer Console开始使用Alexa技能进行技能编程。 因此,我的技能发展水平不是很高,我希望在此处寻求帮助。
我有播放流(m3u)的技能。很好。
我的简单代码在index.js
const Radio1 = {
token: '1',
url: 'https://[...].m3u',
metadata: {
title: 'Radio1',
},
}
const Radio2 = {
token: '2',
url: 'https://[...].m3u',
metadata: {
title: 'Radio2',
},
}
const PlayStreamIntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'LaunchRequest'
},
handle(handlerInput) {
const stream = Radio1;
const speechText = `Starting ${stream.metadata.title}`;
return handlerInput.responseBuilder
.speak(speechText)
.addAudioPlayerPlayDirective('REPLACE_ALL', stream.url, stream.token, 0, null, stream.metadata)
.getResponse();
}
};
除了以例如Alexa start MySkillName
它可以工作,但是现在我想过一会儿(例如10分钟后)触发另一个Intent。
名称为Radio2Intent
,并且已在“意图”部分中定义。
还编写了代码(非常基础):
const Radio2IntentHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'Radio2Intent';
},
handle(handlerInput) {
const stream = Radio2;
const speechText = `Starting ${stream.metadata.title}`;
return handlerInput.responseBuilder
.speak(speechText)
.addAudioPlayerPlayDirective('REPLACE_ALL', stream.url, stream.token, 0, null, stream.metadata)
.getResponse();
}
};
[...]
exports.handler = skillBuilder
.addRequestHandlers(
[...]
Radio2IntentHandler
)
虽然,我可以通过说“将广播2更改为Alexa”来更改流,但它不是:(
我的意图
{
"name": "Radio2Intent",
"slots": [],
"samples": [
"Change to Radio 2"
]
}
也许有人可以在这里帮助我。
谢谢。
答案 0 :(得分:0)
在Github上从Alexa团队中查看multiple-stream-sample。
您需要做的就是使用Audio Player Interface。诀窍是在添加ENQUEUE
时使用REPLACE_ALL
而不是AudioPlayerPlayDirective
。
然后,您应该能够使用“ Alexa,下一个”和“ Alexa,上一个”命令在m3u
流之间导航(请参见NextPlaybackHandler)。