PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, November 19, 2022

[FIXED] How to interrupt an audio recording with the twilio php api

 November 19, 2022     twilio, twilio-api, twilio-php     No comments   

Issue

I'm using the twilio php api and I can't seem to find any way to interrupt the audio files from playing immediately a gather key is pressed.

This is what I have currently

$voiceResponse->gather(['method' => 'POST', 'action' => $storeResponseURL, 'finishOnKey' => '#']);
$voiceResponse->redirect($noResponseURL, ['method' => 'POST']);

Please, I need help on this.


Solution

Twilio developer evangelist here.

In your <Gather> from your example you have the finishOnKey attribute set to "#". So the <Gather> will only finish when your caller presses "#" not any other key.

Your <Gather> doesn't appear to contain any other TwiML either. If you want to be able to interrupt audio then you need to nest a <Say> or <Play> element inside the <Gather>.

If you want to complete the input after just one character, then your best bet is to actually use the numDigits attribute and set it to 1.

Putting that all together, your TwiML generation should look like this:

$voiceResponse = new Twiml();
$gather = $voiceResponse->gather(['method' => 'POST', 'action' => $storeResponseURL, 'numDigits' => '1']);
$gather->play('/gather_audio.mp3');
$voiceResponse->redirect($noResponseURL, ['method' => 'POST']);

Let me know if that helps!



Answered By - philnash
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing