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!