Skip to content

Playing an audio file with alternate synthesis text

Jean-Philippe Gariépy edited this page May 1, 2018 · 3 revisions

It is possible to play altenate content whenever an audio cannot be played (i.e. fetch problem, bad file format, etc). The alternate text can be specified as the second argument of the fromLocation factory method:

Dialogue.java:

//Play an audio file with alternate content
String recordingLocation = context.getContextPath() + "/audio/test.wav";
String alternateText = "This message is played because the audio file could not be fetched";
AudioFile audioFile = AudioFile.fromLocation(recordingLocation, alternateText);
Message message = new Message("recording-message", audioFile);
DialogueUtils.doTurn(message, context);

The alternate text can either be a String or a SpeechSynthesis. Either way, it will generate synthetized speech.


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 message-audio-file-with-alternate 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.