Skip to content

Collecting DTMF with interruptible message

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

This example is very similar to Collecting DTMF. Here, we will allow the user to type the number while the prompt is being played. This behaviour is also known as barge-in.

In order to do that, we use a diffent signature of the addPrompt method. We use the one where you can specify a DtmfRecognition:

Dialogue.java:

Interaction interaction = interaction("get-dtmf")
        .addPrompt(dtmfRecognition, new SpeechSynthesis("Type a number."))
        .build(dtmfRecognition, Duration.seconds(5));

The DtmfRecognition object is used twice in this statement. It is important to understand why:

  1. The fact that we specify a DtmfRecognition in the addPrompt method indicates that the user can perform input while the prompt is playing.
  2. The fact that we specify a DtmfRecognition in the build method indicates that the user can also perform input after the prompts are played.

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 barge-in-dtmf-interaction [email protected]: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.