The Call.playAndGetInput() method

The Call.playAndGetInput() method takes four 'attributes' objects as parameters. Each attributes object contains several attributes that specify such things as prompts for the caller, timeouts and error messages.

The attributes objects that make up the four parameters of the playAndGetInput() method are :
  1. PlayAttributes - used to specify whether the caller can interrupt the messages played as part of a voice or DTMF input.
  2. Either
    • InputAttributes - used to specify the voice segment or sequence of voice segments to be played to the caller, the time to wait for a response, and the validation that will be performed on the caller's input.
    Or
    • MenuAttributes - an extension of class InputAttributes. Has all the attributes of InputAttributes, plus additional attributes used to specify a complete menu with voice segments, identification labels, DTMF selector key responses and recognized selector word responses.
  3. DTMFAttributes - used to specify the maximum number of DTMF key presses allowed in a caller response and also any keys to be used for ending input. Replace with null if DTMF input is not required.
  4. RecoAttributes - used to specify the settings for the speech recognition used for this input. Replace with null if voice input is not required.
As shown above, the second parameter of the Call.playAndGetInput() method varies. The attributes object you use as the second parameter depends on whether you are obtaining data from the user, or are asking the user to make a menu selection:
  • Obtaining data from the caller

    To obtain information such as a telephone number from the caller, use

    Call.playAndGetInput(PlayAttributes playAttributes, InputAttributes inputAttributes, DTMFAttributes dtmfAttributes, RecoAttributes recoAttributes)

  • Getting the caller to make a menu selection

    To get a caller to choose from a list of menu choices, use

    Call.playAndGetInput (PlayAttributes playAttributes, MenuAttributes menuAttributes, DTMFAttributes dtmfAttributes, RecoAttributes recoAttributes)

Storing the various attributes in four separate attributes objects means that you can re-use them elsewhere in the application. For example, you may want all your prompts to be interruptible by DTMF key, but you might want to change the number of DTMF key presses the caller is allowed to use. In this case you could reuse your PlayAttributes object throughout the application, and either create different DTMFAttributes objects according to the requirements of each prompt, or create one DTMFAttributes object and alter it for each prompt.

The Call.playAndGetInput() method returns an InputResult object that represents the caller’s input. See The Caller’s response for more information about the InputResult class.

Example:
public class myVoiceApp extends WVRApplication {
  .
  .
  .
  // Create the attributes objects - use empty constructors so that attributes
  // have default values
  private PlayAttributes myPlayAtts 	= new PlayAttributes();
  private InputAttributes myInputAtts = new InputAttributes();
  private DTMFAttributes myDTMFAtts 	= new DTMFAttributes();
  private RecoAttributes myRecoAtts 	= null;
  // Enter the main application method
  public void VoiceMain() throws WVRException {
    // Create the application properties
    ApplicationProperties appProperties = new ApplicationProperties();
    appProperties.setApplicationName("myApplication");
    applicationProperties.setLocale(Locale.US);
		
    // Create the WVR object, using the application properties
    WVR wvr = new wvr(this, appProperties);
		
    // Create the Call object, using the WVR object
    Call call = wvr.waitForCall();
		
    // Get input from the caller, using the attribute objects created earlier
    InputResult result = call.playAndGetInput(myPlayAtts, myInputAtts, myDTMFAtts, myRecoAtts);
    .
    .
    .
  }//VoiceMain
}	

In the above example, null is used in place of a RecoAttributes object because speech recognition is not used with this prompt.