我正在为Amazon Alexa建立一项技能,该技能可以从网站检索播客并播放。 播客正在正常播放并停止播放,但是尝试停止并恢复播放时出现问题。
首先,亚马逊说我可以说“ Alexa,暂停”或“ Alexa,恢复”来暂停和恢复音频。但是在我的代码中,这会导致技能响应出错,因此我必须使用调用名称才能使它们起作用。
我的第二个问题是,当我暂停音频流时,它停止了。但是当我恢复它时,它从LaunchRequest开始。 它不只是从头开始流式传输。看起来Alexa认为调用“ open mySkill”和“ resume mySkill”是同一件事。但是“恢复”应该是从流媒体暂停之前开始的声音。
我尝试更改参数“ shouldEndSession”,但这不是我想要的,因为它使Alexa等待新的响应,而不是流音频。
这是我的代码的一部分。
SimplePlayer.prototype.handle = function () {
var requestType = this.event.request.type;
var userId = this.event.context ? this.event.context.System.user.userId : this.event.session.user.userId;
var epId = this.id_episode;
//variabile per gestire i diversi linguaggi della richiesta
var requestLang = this.event.request.locale;
// On launch, we tell the user what they can do (Play audio :-))
if (requestType === "LaunchRequest") {
if(requestLang === "en-US")
this.say("Welcome to the commonsense radio. Say Start to play some audio!", "You can say Start");
else if(requestLang === "it-IT")
this.say("Benvenuto nella Radio del Buonsenso. Puoi dire avvia per ascoltare l'ultimo programma!", "You can say Play");
// Handle Intents here - Play, Pause and Resume is all for now
} else if (requestType === "IntentRequest") {
var intent = this.event.request.intent;
if (intent.name === "AvviaRadioIntent") {
this.play(podcastURL + epId + "/play", 0);
} else if (intent.name === "AMAZON.StopIntent") {
// When we receive a Pause Intent, we need to issue a stop directive
// Otherwise, it will resume playing - essentially, we are confirming the user's action
//this.say("stop", "stop");
if(requestLang === "it-IT")
this.stop("Sto terminando la riproduzione come richiesto", "Termino la riproduzione");
else if(requestLang === "en-US")
this.stop("I'm closing the audio stream as requested. ", "Closing the audio stream.");
} else if (intent.name === "AMAZON.PauseIntent") {
this.stop("","");
this.attributes.offsetInMills = this.event.request.offsetInMilliseconds;
} else if (intent.name === "AMAZON.ResumeIntent") {
this.play(podcastURL + epId + "/play", this.attributes.offsetInMills);
} else if (intent.name === "AMAZON.StartOverIntent") {
var lastPlayed = this.loadLastPlayed(userId);
var offsetInMilliseconds = 0;
if (lastPlayed !== null) {
offsetInMilliseconds = lastPlayed.request.offsetInMilliseconds;
}
this.play(podcastURL, offsetInMilliseconds);
} else if (intent.name === "AMAZON.HelpIntent") {
if(requestLang === "en-US")
this.say("Welcome to the Radio del Buonsenso. Say Play to play some audio!", "You can say Play");
else if(requestLang === "it-IT")
this.say("Puoi dire avvia per ascoltare l'ultimo programma!. Invece puoi dire stop radio del buonsenso per interrompere la riproduzione", "Puoi dire avvia per avviare, stop radio del buonsenso per chiudere.");
}
};
这些是我已经实现的播放和停止指令。
SimplePlayer.prototype.play = function (audioURL, offsetInMilliseconds) {
var response = {
version: "1.0",
response: {
shouldEndSession: true,
directives: [
{
type: "AudioPlayer.Play",
playBehavior: "REPLACE_ALL", // Setting to REPLACE_ALL means that this track will start playing immediately
audioItem: {
stream: {
url: audioURL,
token: "0", // Unique token for the track - needed when queueing multiple tracks
expectedPreviousToken: null, // The expected previous token - when using queues, ensures safety
offsetInMilliseconds: offsetInMilliseconds
}
}
}
]
}
};
this.context.succeed(response);
};
// Stops the playback of Audio
SimplePlayer.prototype.stop = function (message, repromptMessage) {
var response = {
version: "1.0",
response: {
shouldEndSession: true,
outputSpeech: {
type: "SSML",
ssml: "<speak> " + message + " </speak>"
},
reprompt: {
outputSpeech: {
type: "SSML",
ssml: "<speak> " + repromptMessage + " </speak>"
}
},
directives: [
{
type: "AudioPlayer.Stop"
}
]
}
};
this.context.succeed(response);
};
当说“ Alexa,暂停”时,如何使技能停止音频?如何从说“ Alexa,恢复”时暂停的状态恢复流?