0

I've got a strange issue with Twilio playing some audio files, while others give errors.

The twiml code is not the issue - here's a simplified version of what I'm using...

<?php
include('route\to\twilio');    
use Twilio\TwiML\VoiceResponse;
$response = new VoiceResponse;
$audio = "https://example.com/2190277108.mp3";
$response->play($audio);
header('Content-Type: text/xml');
echo $response;

The problem is that SOME files just don't play, while others give error codes in Twilio

For this particular .mp3 file, Twilio's Request Inspector shows a 502 error

POST https://example.com/twilio-answer-call.php 2020-06-19 14:13:21 UTC 915ms 200

Request

Response

Headers

Body

<?xml version="1.0" encoding="UTF-8"?> <Response> <Play>https://example.com/2190277108.mp3</Play> </Response>

GET https://example.com/2190277108.mp3 2020-06-19 14:13:23 UTC 1095ms 502

Request

Response

Headers

Content-Type text/html

Body

Twilio was unable to fetch content from: http://example.com/2190277108.mp3

Error: Empty/Invalid Response from Remote Host mydomain.com

Account SID: myTwilioAcct

SID: CA4b1

Request ID: 02-7e8-43-a6-0d448

Remote Host: example.com

Request Method: GET

Request URI: http://example.com/2190277108.mp3

URL Fragment: false

Yet, when I change the .mp3 (and only that...), it plays just fine....

$audio = "https://example.com/AnotherOneBitesTheDust.mp3";

The difference is that, on the 'song' one (that works), I see

Headers Content-Type audio/ulaw

Going directly to each link in Chrome, the audio plays just fine (which means little, other than the link is correct...), however, it fails in Twilio.

I've tried various ways to 'fake' the header (using some php code, various html autoplay, etc.) and can get the Header to be 'audio/ulaw', but the audio doesn't play...

With some variations, I have stacked the audios (the feature I've implemented places various 'stacks' of audio depending on the user's configuration) and again, SOME audio files have different reactions from Twilio.

  • File crashes the call (as detailed above)
  • File is skipped (i.e., the second one plays -first one seems to try, but no audio, then moves on to second)

I've spent hours trying to figure what files work, what doesn't.....

The problem ones are recorded on the PC - some recorded through the browser (I've used various methods, lately using https://github.com/muaz-khan/RecordRTC - all methods five same results...), some directly in Voice Recorder. I've also tried directly uploading the files as well as through PHP upload.

At one point (early in the development, which made me happy - then we found other bugs....) we had files working on Twilio and moved away from those tests as it seemed to work easy and fast. Then, we went back to do some final testing and found this 'some files work' issue.....

So, what I'm looking for is a consistent way to make files work.

What it seems to be is that the recording method isn't giving the right headers when played back directly through Twilio (the purchased song works, while internal PC recordings don't....), though I have no way to really prove that (that I know of - maybe getid3 would help????)

The perfect end result is to have a way to record through the browser, upload and have it play correctly. I've tried .m4a, .wav and .mp3 - all of which give the same results as above (some worked early on, now I can't find the 'magic' combo again.....)

Could be that I've just been at this one issue too long (20 hours or more...) and am missing something simple, but I just can't see it.

Any help/suggestions are welcome! Thanks!

Apps-n-Add-Ons
  • 2,026
  • 1
  • 17
  • 28
  • Twilio, Best Practices for Audio Recordings - https://support.twilio.com/hc/en-us/articles/223180588-Best-Practices-for-Audio-Recordings – Alan Jun 20 '20 at 11:58
  • @Alan, files with the extra processing do work. The User can record the audio (in Chrome, for example with RecordRTC), upload to the server, etc. though Twilio does not play the file (it plays in browsers, in audio programs, players, etc....). If I 'process' it locally (through various programs - 'extra work'...), Twilio plays it just fine. What I'm looking for is a way that the User can record from their browser - and it plays on Twilio... I'm trying an API convertor today - has promise, but still seems something else (some setting in RecordRTC?) should work more simply! – Apps-n-Add-Ons Jun 20 '20 at 13:47
  • @Apps-n-Add-Ons how did you made this work? – Luna Nov 08 '21 at 14:42
  • @Luna - we never found a solution - the client got frustrated and the project was cancelled... – Apps-n-Add-Ons Nov 09 '21 at 15:19
  • this answer I gave to another question might actually be the solution (of course, change from 'image' to 'audio' - but it is a possible solution) https://stackoverflow.com/a/49609600/7981914 – Apps-n-Add-Ons Nov 09 '21 at 15:24
  • @Apps-n-Add-Ons I did find the reason and solution! I'll write an answer for the next person – Luna Nov 09 '21 at 18:09

0 Answers0