Search code examples
twiliotwilio-twiml

Twilio Gather is recording too soon


The following code is used to build up TwiML to ask the caller which department they are looking for.

If the user is already talking when the gather.Say is being read to the caller, then whatever they are saying over the message is being included, as well as their actual answer to the question in the Action url.

The documentation states:

The following example shows a that specifies speech input from the user. When this TwiML executes, the caller will hear the prompt. Twilio will then collect speech input for up to 60 seconds.

However the speech input collection is happening whilst the say is executing.

How do i make sure that whatever is being said whilst the Say is executing is not included as part of the actual response to the question?

   ...

    var call = GetCallData();

    var gather = new Gather(
            timeout: 4,
            input: new List<Gather.InputEnum> { Gather.InputEnum.Speech },
            method: HttpMethod.Post,
            language: call.TwilioLanguage,
            bargeIn: false
            )
        {
            Action = new Uri("MyUrl/Answer/Department")
        };

    gather.Say("Please say the name of the department you wish to be connected to",
        language: call.TwilioLanguage,
        voice: call.TwilioVoice);

    response.Append(gather);

    response.Redirect(new Uri("MyUrl/Hangup"), HttpMethod.Post);

    return TwiML(response);

Solution

  • If you do not nest the Say in the Gather, the caller must listen to the Say before the Gather collects input.

    More details are here.

    TwiML Gather

    "By nesting Say or Play in your Gather, you can read some text or play music for your caller while waiting for their input. See "Nest other verbs" below for examples and more information."