use of com.amazon.speech.speechlet.interfaces.audioplayer.directive.PlayDirective in project amos-ss17-alexa by c-i-ber.
the class TimeTravelService method onIntent.
@Override
public SpeechletResponse onIntent(SpeechletRequestEnvelope<IntentRequest> requestEnvelope) throws SpeechletException {
IntentRequest request = requestEnvelope.getRequest();
Intent intent = request.getIntent();
if (intent.getName().equals(FUTURE_INTENT)) {
// TODO: Insert code that sets up data
String text = "Natürlich, nichts leichter als das. Bitte anschnallen!";
SpeechletResponse response = new SpeechletResponse();
// Back to the future song
List<Directive> directives = new LinkedList<>();
PlayDirective directive = new PlayDirective();
AudioItem audioItem = new AudioItem();
Stream stream = new Stream();
stream.setToken("this-is-the-audio-token");
// temporarily hosted on Julian's server
stream.setUrl("https://files.bitspark.de/bttf.mp3");
audioItem.setStream(stream);
directive.setAudioItem(audioItem);
directive.setPlayBehavior(PlayBehavior.REPLACE_ALL);
directives.add(directive);
response.setDirectives(directives);
// Card
SimpleCard simpleCard = new SimpleCard();
simpleCard.setTitle(CARD_TITLE);
simpleCard.setContent(text);
response.setCard(simpleCard);
// Speech
response.setOutputSpeech(getSSMLOutputSpeech(text));
return response;
} else if (intent.getName().equals(PAST_INTENT)) {
// Create new demo account
// AccountFactory accountFactory = AccountFactory.getInstance();
// Account account = accountFactory.createDemo();
String text = "<prosody rate=\"fast\">Okay! Es geht wieder zurueck. Halte dich fest!</prosody>";
SpeechletResponse response = new SpeechletResponse();
// Back to the future song
List<Directive> directives = new LinkedList<>();
PlayDirective directive = new PlayDirective();
AudioItem audioItem = new AudioItem();
Stream stream = new Stream();
stream.setToken("this-is-the-audio-token");
// temporarily hosted on Julian's server
stream.setUrl("https://files.bitspark.de/bttf.mp3");
audioItem.setStream(stream);
directive.setAudioItem(audioItem);
directive.setPlayBehavior(PlayBehavior.REPLACE_ALL);
directives.add(directive);
response.setDirectives(directives);
// Card
SimpleCard simpleCard = new SimpleCard();
simpleCard.setTitle(CARD_TITLE);
simpleCard.setContent(text);
response.setCard(simpleCard);
// Speech
response.setOutputSpeech(getSSMLOutputSpeech(text));
return response;
}
// Shouldn't happen
assert (false);
return null;
}
Aggregations