Playing an audio file with alternate synthesis text
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:
//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.
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.