Skip to content

Instantly share code, notes, and snippets.

@jkelvie
Last active March 1, 2017 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jkelvie/334c67570cb4b8edcaa828226ae055de to your computer and use it in GitHub Desktop.
Save jkelvie/334c67570cb4b8edcaa828226ae055de to your computer and use it in GitHub Desktop.
Properly Injected SSML
/**
* Creates a {@code SpeechletResponse} for the hello intent.
*
* @return SpeechletResponse spoken and visual response for the given intent
*/
private SpeechletResponse getHelloResponse(Session session) {
String speechText = "Hello world";
// Create the Simple card content.
SimpleCard card = new SimpleCard();
card.setTitle("HelloWorld");
card.setContent(speechText);
SsmlOutputSpeech speech = monetize.injectSSML(session.getUser().getUserId(),
"<speak>Hello! And now a word from our sponsor {ad} What would you like to do?</speak>",
"<speak>Hello! Tell me something!</speak>")
.asSsmlOutputSpeech();
return SpeechletResponse.newTellResponse(speech, card);
}
public void onSessionStarted(final SessionStartedRequest request, final Session session)
throws SpeechletException {
log.info("onSessionStarted requestId={}, sessionId={}", request.getRequestId(),
session.getSessionId());
monetize.prime(session.getUser().getUserId());
// any initialization logic goes here
}
{
"version": "1.0",
"response": {
"outputSpeech": {
"type": "SSML",
"ssml": "<speak>Hello! And now a word from our sponsor <audio src=\"https://s3.amazonaws.com/bespoken-monetization/30-seconds-spot-encoded.mp3\" /><audio src=\"https://monetization.bespoken.tools/v1/track?requestID=d42a4120-fe95-11e6-a1dc-35c4036ba0ea\" /> What would you like to do?</speak>"
},
"card": {
"type": "Simple",
"title": "HelloWorld",
"content": "Hello world"
},
"shouldEndSession": true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment