Gathering speech during outbound twilio voice call

675 views Asked by At

I am trying to create a voice call from twilio to a number using programmable voice. I also intend to gather recipient's speech transcribed. However, the documentation contains examples and tutorials only for inbound voice calls.

This is what I have tried-

Initiating voice call:

  client.calls
  .create({
    twiml: `<Response><Gather input="speech" action="https://ngrok-url-for-my-local-server/voice" method="POST" speechTimeout="5"><Say>Hey there, How are you?</Say><Pause length="4" /></Gather></Response>`,
    to: toPhoneNumber,
    from: myPhoneNumber,
  })
  .then((call) => {
    console.log(call.sid)
    console.log(call)
  })
  .catch((e) => {
    console.log(e)
  })

Code in handler for gathering speech-

const VoiceResponse = twiml.VoiceResponse

const res = new VoiceResponse()
res.gather()
console.log(res.toString())

However I am not getting anything useful in the console. Can anybody point me to a useful tutorial or example or tell me what I should do ?

1

There are 1 answers

2
jassent On

You need to first make the call and then modify the call to gather.

When you make the call using the new VoiceResponse() call you will be returned a SID for the call. Next, use that SID to modify a call that is in progress by redirecting to the Twiml to gather the digits.

You will have three legs:

  1. Make the outbound call (you provided this code in your questions).
  2. Modify the active outbound call by using the call's SID to redirect to a Gather twiml.
  3. After the gather has finished tell the call what do to using the action parameter of the gather. Here is an example.

If you are trying to go for a conference bridge type feature where you press * to move into an admin type menu, you will need a more complex solution involving a conference call.