/** * 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. */ private SpeechletResponse getAskResponse(String cardTitle, String speechText) { SimpleCard card = getSimpleCard(cardTitle, speechText); PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText); Reprompt reprompt = getReprompt(speech); return SpeechletResponse.newAskResponse(speech, reprompt, card); } }
/** * Gets a random new fact from the list and returns to the user. */ private SpeechletResponse getNewFactResponse() { // Get a random space fact from the space facts list int factIndex = (int) Math.floor(Math.random() * SPACE_FACTS.length); String fact = SPACE_FACTS[factIndex]; // Create speech output String speechText = "Here's your space fact: " + fact; // Create the Simple card content. SimpleCard card = getSimpleCard("SpaceGeek", speechText); // Create the plain text output. PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText); return SpeechletResponse.newTellResponse(speech, card); }
SpeechletResponse build() { SpeechletResponse response = new SpeechletResponse(); response.setOutputSpeech(speech); response.setCard(card); response.setReprompt(reprompt); response.setDirectives(directiveList); response.setNullableShouldEndSession(shouldEndSession); return response; }
private static SpeechletResponse buildResponse(String text) { final PlainTextOutputSpeech output = new PlainTextOutputSpeech(); output.setText(text); final SpeechletResponse response = new SpeechletResponse(); response.setOutputSpeech(output); return response; } }
return SpeechletResponse.newTellResponse(outputSpeech, card); } else { session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); return SpeechletResponse.newAskResponse(outputSpeech, repromptSpeech, card); SpeechletResponse response = newAskResponse(speechOutput, false, repromptText, false); response.setCard(card); return response;
/** * Returns a Speechlet response for a speech and reprompt text. */ private SpeechletResponse getSpeechletResponse(String speechText, String repromptText, boolean isAskResponse) { // Create the Simple card content. SimpleCard card = new SimpleCard(); card.setTitle("Session"); card.setContent(speechText); // Create the plain text output. PlainTextOutputSpeech speech = new PlainTextOutputSpeech(); speech.setText(speechText); if (isAskResponse) { // Create reprompt PlainTextOutputSpeech repromptSpeech = new PlainTextOutputSpeech(); repromptSpeech.setText(repromptText); Reprompt reprompt = new Reprompt(); reprompt.setOutputSpeech(repromptSpeech); return SpeechletResponse.newAskResponse(speech, reprompt, card); } else { return SpeechletResponse.newTellResponse(speech, card); } } }
outputSpeech.setSsml("<speak>" + speechOutput + "</speak>"); return SpeechletResponse.newTellResponse(outputSpeech); } else { StringBuilder speechOutputBuilder = new StringBuilder(); response.setCard(card); return response;
response.setCard(card); return response;
return SpeechletResponse.newTellResponse(outputSpeech, card); } else { session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); return SpeechletResponse.newAskResponse(outputSpeech, repromptSpeech, card); SpeechletResponse response = newAskResponse(speechOutput, false, repromptText, false); response.setCard(card); return response;
/** * Returns a Speechlet response for a speech and reprompt text. */ private SpeechletResponse getSpeechletResponse(String speechText, String repromptText, boolean isAskResponse) { // Create the Simple card content. SimpleCard card = new SimpleCard(); card.setTitle("Session"); card.setContent(speechText); // Create the plain text output. PlainTextOutputSpeech speech = new PlainTextOutputSpeech(); speech.setText(speechText); if (isAskResponse) { // Create reprompt PlainTextOutputSpeech repromptSpeech = new PlainTextOutputSpeech(); repromptSpeech.setText(repromptText); Reprompt reprompt = new Reprompt(); reprompt.setOutputSpeech(repromptSpeech); return SpeechletResponse.newAskResponse(speech, reprompt, card); } else { return SpeechletResponse.newTellResponse(speech, card); } } }
PlainTextOutputSpeech outputSpeech = new PlainTextOutputSpeech(); outputSpeech.setText("There was an error looking up best sellers. Please try again later."); return SpeechletResponse.newTellResponse(outputSpeech); output.setSsml("<speak>I'm sorry, I cannot get the top sellers for " + category + " at this time. Please try again later. Goodbye.</speak>"); return SpeechletResponse.newTellResponse(output); response.setCard(card);
/** * Selects a joke randomly and starts it off by saying "Knock knock". * * @param session * the session object * @return SpeechletResponse the speechlet response */ private SpeechletResponse handleTellMeAJokeIntent(final Session session) { String speechOutput = ""; // Reprompt speech will be triggered if the user doesn't respond. String repromptText = "You can ask, who's there"; // / Select a random joke and store it in the session variables int jokeID = (int) Math.floor(Math.random() * JOKE_LIST.size()); // The stage variable tracks the phase of the dialogue. // When this function completes, it will be on stage 1. session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); session.setAttribute(SESSION_JOKE_ID, jokeID); speechOutput = "Knock knock!"; // Create the Simple card content. SimpleCard card = new SimpleCard(); card.setTitle("Wise Guy"); card.setContent(speechOutput); SpeechletResponse response = newAskResponse(speechOutput, false, repromptText, false); response.setCard(card); return response; }
/** * Gets a random new fact from the list and returns to the user. */ private SpeechletResponse getNewFactResponse() { // Get a random space fact from the space facts list int factIndex = (int) Math.floor(Math.random() * SPACE_FACTS.length); String fact = SPACE_FACTS[factIndex]; // Create speech output String speechText = "Here's your space fact: " + fact; // Create the Simple card content. SimpleCard card = getSimpleCard("SpaceGeek", speechText); // Create the plain text output. PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText); return SpeechletResponse.newTellResponse(speech, card); }
/** * 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. */ private SpeechletResponse getAskResponse(String cardTitle, String speechText) { SimpleCard card = getSimpleCard(cardTitle, speechText); PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText); Reprompt reprompt = getReprompt(speech); return SpeechletResponse.newAskResponse(speech, reprompt, card); } }
PlainTextOutputSpeech outputSpeech = new PlainTextOutputSpeech(); outputSpeech.setText("There was an error looking up best sellers. Please try again later."); return SpeechletResponse.newTellResponse(outputSpeech); output.setSsml("<speak>I'm sorry, I cannot get the top sellers for " + category + " at this time. Please try again later. Goodbye.</speak>"); return SpeechletResponse.newTellResponse(output); response.setCard(card);
SpeechletResponse build() { SpeechletResponse response = new SpeechletResponse(); response.setOutputSpeech(speech); response.setCard(card); response.setReprompt(reprompt); response.setDirectives(directiveList); response.setNullableShouldEndSession(shouldEndSession); return response; }
/** * Selects a joke randomly and starts it off by saying "Knock knock". * * @param session * the session object * @return SpeechletResponse the speechlet response */ private SpeechletResponse handleTellMeAJokeIntent(final Session session) { String speechOutput = ""; // Reprompt speech will be triggered if the user doesn't respond. String repromptText = "You can ask, who's there"; // / Select a random joke and store it in the session variables int jokeID = (int) Math.floor(Math.random() * JOKE_LIST.size()); // The stage variable tracks the phase of the dialogue. // When this function completes, it will be on stage 1. session.setAttribute(SESSION_STAGE, KNOCK_KNOCK_STAGE); session.setAttribute(SESSION_JOKE_ID, jokeID); speechOutput = "Knock knock!"; // Create the Simple card content. SimpleCard card = new SimpleCard(); card.setTitle("Wise Guy"); card.setContent(speechOutput); SpeechletResponse response = newAskResponse(speechOutput, false, repromptText, false); response.setCard(card); return response; }
/** * Creates a {@code SpeechletResponse} for the GetAddress intent. * @return SpeechletResponse spoken and visual response for the given intent */ private SpeechletResponse getAddressResponse(String streetName, String state, String zipCode) { String speechText = "Your address is " + streetName + " " + state + ", " + zipCode; SimpleCard card = getSimpleCard(ADDRESS_CARD_TITLE, speechText); PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText); return SpeechletResponse.newTellResponse(speech, card); }
/** * 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. */ private SpeechletResponse getAskResponse(String cardTitle, String speechText) { SimpleCard card = getSimpleCard(cardTitle, speechText); PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText); Reprompt reprompt = getReprompt(speech); return SpeechletResponse.newAskResponse(speech, reprompt, card); } }
/** * Creates a {@code SpeechletResponse} for the hello intent. * * @return SpeechletResponse spoken and visual response for the given intent */ private SpeechletResponse getHelloResponse() { String speechText = "Hello world"; // Create the Simple card content. SimpleCard card = getSimpleCard("HelloWorld", speechText); // Create the plain text output. PlainTextOutputSpeech speech = getPlainTextOutputSpeech(speechText); return SpeechletResponse.newTellResponse(speech, card); }