Use Play and Record

  1. Home
  2. Programmable Voice
  3. How do I
  4. Use Play and Record

Use Play and Record

Often you will want to play messages or record users. This is done by issuing commands on the Voice Resource. The play and record commands on the Voice Resource class have built in features that make developing voice applications easier. However, they may be a little confusing to developers that are just starting to write voice applications.

Barge In Capability

In voice applications, it is very common for users to have the ability to skip listening to a message in its entirety and begin entering DTMF digits. By setting the Termination Digits of a Voice Resource to “ANY” or “@” play will immediately be stopped. To keep the digits that are entered during a play message, be sure to set ClearDigitBuffer to false.

Below is an example:

VoiceResource m_VoiceResource = chResource.VoiceResource;
// We'll set the termination digits to ANY so that when a user begins entering digits the play commands are interrupted
m_VoiceResource.TerminationDigits = "ANY";
m_VoiceResource.ClearDigitBuffer = false;
m_VoiceResource.Play(RecordingsLocation + "Welcome.WAV");
// If a user begins entering digits during play of Welcome.WAV, Welcome.WAV will stop playing and all Play commands will not execute until GetDigits is called.  The user will not hear EnterZipCode.WAV
m_VoiceResource.Play(RecordingsLocation + "EnterZipCode.WAV");
// Waits until termination conditions are met
// This will retrieve the numbers in the digit buffer
string digitsEntered = m_VoiceResource.DigitBuffer;

Termination Codes

Sometimes you want multiple conditions to be able to stop a command on a Voice Resource. For example, let’s say you are building a conference application and you want users to record their name so that it is played when they enter the conference. You don’t want their recording to have several seconds of silence, and you want to make sure that it is short. You could do something like the following:

VoiceResource m_VoiceResource = chResource.VoiceResource;
// Set the # key as a button to prease before recording
m_VoiceResource.TerminationDigits = "#";
// Make sure that the recording will only last up to 10 seconds
m_VoiceResource.MaximumTime = 10;
// only allow a maximum of 2 seconds of silence
m_VoiceResource.MaximumSilence = 2;
// Record the voice resource and set the termination code to the condition that caused the termination
TerminationCode tc = m_VoiceResource.Record(RecordingsLocation + UniqueID + ".WAV");

// If you would like you can handle the termination code differently
switch (tc)
    case TerminationCode.MaximumTime:
        // do something
    case TerminationCode.MaximumSilence:
        // do something
    case TerminationCode.Digit:
        // do something
        // do something else
Was this article helpful to you? No Yes 14

How can we help?