I need to play mp3 file for a caller. In my website I have a section where I upload files for each number that I bought by twilio. Now I need to connect this files with twilio. As soos as someone calls by this number, that files must be played.
Asked
Active
Viewed 568 times
-1
-
1Did you check the docs? Because it's in the docs. – aergistal Dec 17 '15 at 13:27
-
2I'd say... no they didn't. – ajtrichards Dec 17 '15 at 13:28
1 Answers
3
To play an MP3 file once the Twilio call connects you need to use the following Twiml. The key here is the <Play>
verb.
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play>URL TO YOUR MP3 FILE</Play>
</Response>
As an example from the Twilio Docs:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Play loop="10">https://api.twilio.com/cowbell.mp3</Play>
</Response>
I'd highly recommend reading the Twilo documentation, it's outstanding!

ajtrichards
- 29,723
- 13
- 94
- 101
-
-
Ok that's fine. You'd have to create a file for each number, that is accessible at specific URLs. You then configure your Twilio application to point to that file depending on the number dialled. – ajtrichards Dec 17 '15 at 13:30
-
There are a lot of numbers. it must be dynamic. I must not configure it via Twilio account. – user3351236 Dec 17 '15 at 13:32
-
Ok then configure the endpoint for all numbers to go to the same PHP file and use PHP to insert a different file name depending on the number. Have you tried writing any code to achieve this? – ajtrichards Dec 17 '15 at 13:34
-
I just need to add "VoiceUrl" to already bought number via api, but i can't find it. – user3351236 Dec 17 '15 at 13:43
-
So you want to pass a parameter (Containing the MP3 URL) to your TWIML script? – ajtrichards Dec 17 '15 at 13:44
-
You can update the VoiceUrl of a phone number by POSTing to the phone number's endpoint. Check out the docs here: https://www.twilio.com/docs/api/rest/incoming-phone-numbers#instance-post – philnash Dec 17 '15 at 13:47