0

In alexa response builder, how listen user response after .addAudioPlayerPlayDirective() ?

return handlerInput.responseBuilder
  .speak(speechText)
  .addAudioPlayerPlayDirective(
    "REPLACE_ALL",
    "https://firebasestorage.googleapis.com/v0/b/quizzfilm.appspot.com/o/Bientot-lepoque-viendra-ou-les-Hobbits-determineront-le-destin-de-tous.mp3?alt=media&token=7e5f570a-4e99-48a4-a473-e052d579ddcb",
    "12345"
  )
  .withShouldEndSession(false)
  .getResponse();
Kalamarico
  • 5,466
  • 22
  • 53
  • 70
Symfomany
  • 1
  • 1

1 Answers1

1

You cannot start a playback and wait for user response. Even during a playback, a user can only trigger build-in playback control intents.


When you send a AudioPlayer.Play directive with a playBehavior="REPLACE_ALL", Alexa begins the playback of the specified stream, and replace current and enqueued streams. While sending a Play directive, you normally set the shouldEndSession flag in the response object to true to end the session. If you set this flag to false, Alexa sends the stream to the device for playback, then immediately pauses the stream to listen for the user's response.

In ask-nodejs-sdk shouldEndSession flag is automatically false if you include a reprompt(). As a result as soon Alexa receives this response it speaks the speech and reprompt and wait for user response (shouldEndSession=false). If no response is there it will end the session as usual and the stream would never be played.

When your skill sends a Play directive (shouldEndSession flag set to true) to begin playback, the Alexa service sends the audio stream to the device for playback. Once the session ends normally(when it begins playback), Alexa remembers that your skill started the playback and during this time, users can invoke any of the built-in playback control intents without using your skill's invocation name.

If you want to let the user guess a music that was played, you can use audio tag of SSML. So that once the audio is played, it will wait for user response.

<speak>
    Guess this music 
    <audio src="https://yoursoundsource.com/path/to/music.mp3" /> 
</speak> 

Note: The audio file cannot be longer than ninety (90) seconds.

More on audio tag here.
More on AudioPlayer directives here.

johndoe
  • 4,387
  • 2
  • 25
  • 40