我正在尝试使用 AudioPlayer 在 Alexa 上启动广播流。 用户应该能够通过使用插槽选择两个本地无线电台之一。那部分正在工作。
启动意图时,代码不会抛出任何错误。但是无线电流没有启动(甚至没有在我的本地 Dot 上)。
在我看来,代码还在等待什么,但我无法弄清楚缺少什么。
CompletedLocalRadioIntentHandler : {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& request.intent.name === 'LocalRadioIntent'
&& request.dialogState === 'COMPLETED';
},
handle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
//const filledSlots = request.intent.slots;
//const slotValues = getSlotValues(filledSlots);
//const key = `${slotValues.RadioStation.key}`;
// const radioURL = `${slotsToOptionsMap[key]}`;
const radioUrl = 'https://wdr-1live-live.sslcast.addradio.de/wdr/1live/live/mp3/128/stream.mp3';
return handlerInput.responseBuilder
.addDirective({
shouldEndSession: true,
type: 'AudioPlayer.Play',
playBehavior: 'REPLACE_ALL',
audioItem: {
stream: {
token: "0",
url: radioUrl,
expectedPreviousToken: null,
offsetInMilliseconds: 0
},
}
})
},
}
音频播放器接口的常见问题是严格的音频要求,这看起来是您问题的原因。 Amod 提供的链接适用于 SSML 而不是音频播放器。确保遵循音频流的所有要求:
-Audio file must be hosted at an Internet-accessible HTTPS endpoint on port 443.
-The web server must present a valid and trusted SSL certificate. Self-signed certificates are not allowed (really important).Many content hosting services provide this. For example, you could host your files at a service such as Amazon Simple Storage Service (Amazon S3) (an Amazon Web Services offering).
-If the stream is a playlist container that references additional streams, each stream within the playlist must also be hosted at an Internet-accessible HTTPS endpoint on 443 with a valid and trusted SSL certificate.
-The supported formats for the audio file include AAC/MP4, MP3, PLS, M3U/M3U8, and HLS. Bitrates: 16kbps to 384 kbps.
此信息可在以下官方文档中找到:https://developer.amazon.com/en-US/docs/alexa/custom-skills/audioplayer-interface-reference.html#audio-stream-requirements
有一个AudioPlayer 示例技巧,它实际上是从一个广播电台流出来的,您可以参考。可以在这里找到:https://github.com/alexa-samples/skill-sample-nodejs-audio-player
您需要更改 url 流并添加您自己的。