Skip to content

Recording with playback

Jean-Philippe Gariépy edited this page Apr 25, 2015 · 2 revisions

It is sometimes useful to play back the recorded message to the user in order to get a confirmation. To do that, we just need to temporarly store the audio on the VoiceXML platform. To do that, we do the same thing as in Recording except that we add the following:

Dialogue.java:

recording.setClientSideAssignationDestination("application.recording");

This will store the recorded audio in a VoiceXML variable in the application scope (we will need it later in the dialogue, that's why we need to put it in the application scope).

To play back the message, we need to use the AudioFile audio item. Since we are going to play a previously recorded file which is stored in a VoiceXML variable, we need to build this AudioFile from a JavaScript expression:

Dialogue.java:

Message playbackMessage = new Message("playback",
                                      new SpeechSynthesis("Here's your message: "),
                                      AudioFile.fromExpression("application.recording"));

Running this example

You can download or browse the complete code for this example at GitHub.This is a complete working application that you can build and run for yourself.

You can also clone the Rivr Cookbook repository and checkout this example:

git clone -b recording-to-variable git@github.com:nuecho/rivr-cookbook.git

Then, to build and run it:

cd rivr-cookbook

./gradlew jettyRun

The VoiceXML dialogue should be available at http://localhost:8080/rivr-cookbook/dialogue

To stop the application, press Control-C in the console.