Learn to record phone calls with Twilio Programmable Voice. For incoming calls, use the TwiML <Record> verb. For outbound calls, send a POST request with the record parameter to the /Calls.json endpoint. To enable self-service automation, create an inbound call center or outbound call center, make calls with virtual agents, use call tracking, or create transcriptions for AI or ML, follow this guide.
Say instructions= newSay.Builder("Hello. Please leave a message after the beep.").build();
20
21
// Use <Record> to record the caller's message
22
Record record= newRecord.Builder().build();
23
24
// End the call with <Hangup>
25
Hangup hangup= newHangup();
26
27
// Create a TwiML builder object
28
VoiceResponse twiml= newVoiceResponse.Builder()
29
.say(instructions)
30
.record(record)
31
.hangup(hangup)
32
.build();
33
34
// Render TwiML as XML
35
response.setContentType("text/xml");
36
37
try{
38
response.getWriter().print(twiml.toXml());
39
}catch(TwiMLExceptione) {
40
e.printStackTrace();
41
}
42
43
44
45
}
46
}
Ruby requires Sinatra and the Twilio Ruby helper library as noted in the prerequisites.
Record part of an incoming call
1
# Get twilio-ruby from twilio.com/docs/ruby/install
2
require'sinatra'
3
require'twilio-ruby'
4
5
post'/record'do
6
Twilio::TwiML::VoiceResponse.new do|r|
7
# Use <Say> to give the caller some instructions
8
r.say(message:'Hello. Please leave a message after the beep.')
9
10
# Use <Record> to record the caller's message
11
r.record
12
13
# End the call with <Hangup>
14
r.hangup
15
end.to_s
16
end
This code generates a <Record> TwiML document then sends it to Twilio. Twilio consumes the instructions in this TwiML document and records the call. To set additional parameters, see the <Record> documentation.
Record an outbound call
To record an outbound call, create a call that includes the record parameter.
PythonNode.jsPHPC# or .NETJavaRuby
With your credentials, instantiate a Twilio Python SDK client for the Twilio API.
Pass the record parameter to the client.calls.create method. Twilio records the entire phone call.
Record an outbound call
1
# Download the helper library from https://www.twilio.com/docs/python/install
2
importos
3
fromtwilio.restimportClient
4
5
# Find your Account SID and Auth Token at twilio.com/console
6
# and set the environment variables. See http://twil.io/secure
7
account_sid=os.environ["TWILIO_ACCOUNT_SID"]
8
auth_token=os.environ["TWILIO_AUTH_TOKEN"]
9
client=Client(account_sid, auth_token)
10
11
call=client.calls.create(
12
record=True,
13
url="http://demo.twilio.com/docs/voice.xml",
14
to="+14155551212",
15
from_="+15017122661",
16
)
17
18
print(call.sid)
With your credentials, instantiate a Twilio Node.js SDK client for the Twilio API.
Pass the record parameter to the client.calls.create() method. Twilio records the entire phone call.
Record an outbound call
1
// Download the helper library from https://www.twilio.com/docs/node/install
2
consttwilio=require("twilio");// Or, for ESM: import twilio from "twilio";
3
4
// Find your Account SID and Auth Token at twilio.com/console
5
// and set the environment variables. See http://twil.io/secure
6
constaccountSid=process.env.TWILIO_ACCOUNT_SID;
7
constauthToken=process.env.TWILIO_AUTH_TOKEN;
8
constclient=twilio(accountSid, authToken);
9
10
async functioncreateCall() {
11
constcall= awaitclient.calls.create({
12
from:"+15017122661",
13
record:true,
14
to:"+14155551212",
15
url:"http://demo.twilio.com/docs/voice.xml",
16
});
17
18
console.log(call.sid);
19
}
20
21
createCall();
With your credentials, instantiate a Twilio PHP SDK client for the Twilio API. Pass the parameter to the $client->calls->create() method. Twilio records the entire phone call.
Record an outbound call
1
<?php
2
3
// Update the path below to your autoload.php,
4
// see https://getcomposer.org/doc/01-basic-usage.md
5
require_once"/path/to/vendor/autoload.php";
6
7
useTwilio\Rest\Client;
8
9
// Find your Account SID and Auth Token at twilio.com/console
10
// and set the environment variables. See http://twil.io/secure
11
$sid=getenv("TWILIO_ACCOUNT_SID");
12
$token=getenv("TWILIO_AUTH_TOKEN");
13
$twilio= newClient($sid, $token);
14
15
$call=$twilio->calls->create(
16
"+14155551212",// To
17
"+15017122661",// From
18
[
19
"record"=>true,
20
"url"=>"http://demo.twilio.com/docs/voice.xml",
21
],
22
);
23
24
print$call->sid;
Set the record parameter to the true. Twilio records the entire phone call.
Record an outbound call
1
// Install the C# / .NET helper library from twilio.com/docs/csharp/install
2
3
usingSystem;
4
usingTwilio;
5
usingTwilio.Rest.Api.V2010.Account;
6
usingSystem.Threading.Tasks;
7
8
classProgram{
9
public static asyncTaskMain(string[]args) {
10
// Find your Account SID and Auth Token at twilio.com/console
11
// and set the environment variables. See http://twil.io/secure
To get a notification of a completed recording through a Webhook, pass the Webhook URL as the value of the RecordingStatusCallback parameter for your Recording. When the recording finishes, Twilio sends a request to this URL. In this webhook payload, the RecordingUrl property value has the link to the recording audio file.
Create an inbound call center with Twilio Programmable Voice
You can use this guide to create a programmatic inbound call center that records calls and handles customer inquiries.
To learn more advanced features that you can use with inbound call centers, see Inbound call center.
Create an outbound call center with Twilio Programmable Voice
You can use this guide to record outbound calls that you make from an outbound call center.
To learn more advanced features that you can use with outbound call centers, see Outbound call center.
Make calls with virtual agents with Twilio Programmable Voice
You can use this guide to record calls that you make and handle with virtual AI-powered agents.
To learn more advanced features that you can use with virtual agents, see AI agents.
Use call tracking with Twilio Programmable Voice
By monitoring active links, recording phone conversations, and assessing how interactions map to specific phone routing flows, you can programmatically implement robust call tracking.
To learn more about how to implement call tracking, see Call tracking.
Create transcriptions for AI or ML with Twilio Programmable Voice
You can use this guide to capture the audio of your outbound calls for AI-driven analysis. By recording the call, you can send raw audio to machine learning models for real-time transcription, sentiment analysis, or post-call summarization.
After following this guide, you can record inbound and outbound calls programmatically with Twilio Programmable Voice. You might also have configured webhooks by using the RecordingStatusCallback parameter to track and manage call audio files as soon as they complete.
Next steps
Explore the following guides to build on what you've learned in this guide: