Search in sources :

Example 6 with SpeechletResponse

use of com.amazon.speech.speechlet.SpeechletResponse in project amos-ss17-alexa by c-i-ber.

the class AmosAlexaSpeechletTest method performIntent.

private String performIntent(String intent, String... params) throws IOException, NoSuchFieldException, IllegalAccessException {
    String[] slots = new String[params.length];
    int i = 0;
    for (String param : params) {
        slots[i] = param;
        i++;
    }
    AmosAlexaSpeechlet amosAlexaSpeechlet = AmosAlexaSpeechlet.getInstance();
    SpeechletResponse response = amosAlexaSpeechlet.onIntent(getEnvelope(intent, slots));
    return getOutputSpeechText(response.getOutputSpeech()).replaceAll("\\<.*?>", // Remove all markup since it is not really relevant for our tests
    "");
}
Also used : SpeechletResponse(com.amazon.speech.speechlet.SpeechletResponse)

Example 7 with SpeechletResponse

use of com.amazon.speech.speechlet.SpeechletResponse in project amos-ss17-alexa by c-i-ber.

the class AbstractSpeechService method getAskResponse.

/**
 * Helper method for retrieving an Ask response with a simple card and reprompt included.
 *
 * @param cardTitle  Title of the card that you want displayed.
 * @param speechText speech text that will be spoken to the user.
 * @return the resulting card and speech text.
 */
protected SpeechletResponse getAskResponse(String cardTitle, String speechText) {
    SimpleCard card = getSimpleCard(cardTitle, speechText);
    PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText);
    Reprompt reprompt = getReprompt(speech);
    SpeechletResponse response = SpeechletResponse.newAskResponse(speech, reprompt, card);
    response.setShouldEndSession(false);
    return response;
}
Also used : SpeechletResponse(com.amazon.speech.speechlet.SpeechletResponse)

Example 8 with SpeechletResponse

use of com.amazon.speech.speechlet.SpeechletResponse in project amos-ss17-alexa by c-i-ber.

the class AbstractSpeechService method getErrorResponse.

/**
 * Gets error response.
 *
 * @param errorDetail error details
 * @return the error response
 */
protected SpeechletResponse getErrorResponse(String errorDetail) {
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    // speech.setText("Ein Fehler ist aufgetreten. " + errorDetail);
    speech.setText("");
    SpeechletResponse response = SpeechletResponse.newTellResponse(speech);
    response.setShouldEndSession(true);
    return response;
}
Also used : SpeechletResponse(com.amazon.speech.speechlet.SpeechletResponse)

Example 9 with SpeechletResponse

use of com.amazon.speech.speechlet.SpeechletResponse 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;
}
Also used : Intent(com.amazon.speech.slu.Intent) AudioItem(com.amazon.speech.speechlet.interfaces.audioplayer.AudioItem) SpeechletResponse(com.amazon.speech.speechlet.SpeechletResponse) PlayDirective(com.amazon.speech.speechlet.interfaces.audioplayer.directive.PlayDirective) IntentRequest(com.amazon.speech.speechlet.IntentRequest) SimpleCard(com.amazon.speech.ui.SimpleCard) Stream(com.amazon.speech.speechlet.interfaces.audioplayer.Stream) Directive(com.amazon.speech.speechlet.Directive) PlayDirective(com.amazon.speech.speechlet.interfaces.audioplayer.directive.PlayDirective)

Aggregations

SpeechletResponse (com.amazon.speech.speechlet.SpeechletResponse)9 Intent (com.amazon.speech.slu.Intent)1 Directive (com.amazon.speech.speechlet.Directive)1 IntentRequest (com.amazon.speech.speechlet.IntentRequest)1 AudioItem (com.amazon.speech.speechlet.interfaces.audioplayer.AudioItem)1 Stream (com.amazon.speech.speechlet.interfaces.audioplayer.Stream)1 PlayDirective (com.amazon.speech.speechlet.interfaces.audioplayer.directive.PlayDirective)1 SimpleCard (com.amazon.speech.ui.SimpleCard)1