Back to Blog
Language How-Tos

How to Record and Transcribe a Phone Call in Twilio Using PHP

Enable call recording in Twilio from PHP and receive transcription webhooks to automatically convert recorded calls to text.

DA
Danial A
Senior Twilio Consultant, Telphi Consulting
June 22, 2026
8 min read
Twilio
PHP
How-To
Code
How to Record and Transcribe a Phone Call in Twilio Using PHP

This tutorial shows how to enable call recording in PHP using the Twilio REST API and receive automatic transcriptions via webhook after the call ends. It targets PHP developers building call logging systems, quality assurance tools, or transcript-based analytics who want Twilio to handle audio capture and speech-to-text conversion. You will enable recording on a call with a record option, build a recording status callback PHP endpoint, and access the transcription text once Twilio finishes processing.

Prerequisites and Setup

Install the packages with composer require twilio/sdk vlucas/phpdotenv and expose your local PHP server with ngrok so Twilio can reach your callback endpoints. Twilio records calls server-side without any client configuration; the audio is stored on Twilio's servers until you delete it or it expires. Configure a recordingStatusCallback URL pointing to a PHP script so your server is notified when the recording file is ready, which typically occurs within 30 to 60 seconds of the call ending. Transcription takes an additional 1 to 5 minutes after the recording is ready, depending on call duration, and is delivered to a separate transcribeCallback URL you set on the TwiML Record verb.

composer require twilio/sdk vlucas/phpdotenv

# .env
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN=your_auth_token_here
TWILIO_PHONE_NUMBER=+15551234567

The Complete Code

Pass 'record' => true and a 'recordingStatusCallback' URL to calls->create() to enable recording and receive a webhook when the audio file is ready. The TwiML voice.php endpoint uses the record() method on a VoiceResponse with transcribe set to true and a transcribeCallback URL so Twilio both records and transcribes the caller's message. The recording callback PHP script reads $_POST['RecordingSid'], $_POST['RecordingUrl'], and $_POST['RecordingDuration'] from the POST body. The transcription callback reads $_POST['TranscriptionText'] and $_POST['TranscriptionSid'] once the speech-to-text processing completes.

<?php
// make-call.php
require_once 'vendor/autoload.php';
use TwilioRestClient;

$dotenv = DotenvDotenv::createImmutable(__DIR__);
$dotenv->load();
$client = new Client($_ENV['TWILIO_ACCOUNT_SID'], $_ENV['TWILIO_AUTH_TOKEN']);

$call = $client->calls->create(
    '+15551234567',
    $_ENV['TWILIO_PHONE_NUMBER'],
    [
        'url'                     => 'https://xxxx.ngrok.io/voice.php',
        'record'                  => true,
        'recordingStatusCallback' => 'https://xxxx.ngrok.io/recording-status.php',
    ]
);
echo 'Call SID: ' . $call->sid . PHP_EOL;
<?php
// voice.php
require_once 'vendor/autoload.php';
use TwilioTwiMLVoiceResponse;

$response = new VoiceResponse();
$response->say('This call is being recorded. Please leave your message after the tone.', ['voice' => 'alice']);
$response->record([
    'timeout'             => 10,
    'transcribe'          => true,
    'transcribeCallback'  => 'https://xxxx.ngrok.io/transcription.php',
]);
$response->say('Thank you. Goodbye.', ['voice' => 'alice']);
header('Content-Type: text/xml');
echo $response;
<?php
// recording-status.php
$sid      = $_POST['RecordingSid']      ?? '';
$url      = $_POST['RecordingUrl']      ?? '';
$duration = $_POST['RecordingDuration'] ?? '';
error_log('Recording ready: ' . $sid . ' (' . $duration . 's) ' . $url);
http_response_code(204);
<?php
// transcription.php
$text = $_POST['TranscriptionText'] ?? '';
$sid  = $_POST['TranscriptionSid']  ?? '';
error_log('Transcript [' . $sid . ']: ' . $text);
http_response_code(204);

Testing and Debugging

Start the server and ngrok, run make-call.php, speak for 10 to 15 seconds, and hang up. Within 30 to 60 seconds the recording callback should fire and log the SID and URL, followed a few minutes later by the transcription callback with the text. If no recording callback arrives, verify the ngrok tunnel is running and the recordingStatusCallback URL in your create call is the correct HTTPS ngrok address followed by /recording-status.php. Check the Twilio Console under Monitor, Recordings to verify the audio file exists before debugging the webhook, which confirms recording is working even if the callback is failing.

Taking It Further

Download the recording MP3 by appending .mp3 to the RecordingUrl using PHP's file_get_contents() or a Guzzle HTTP client and store it in S3 using the AWS SDK for PHP for long-term retention. Run the transcription text through PHP string functions or a regex to scan for keywords, flagging calls that mention complaints, cancellations, or competitor names for human review. Store each transcript in a database table with a full-text index so the call centre team can search across all transcripts by keyword. Delete recordings from Twilio after download by calling $client->recordings($sid)->delete() to reduce Twilio storage costs once you have your own S3 copy.

Talk to Telphi Consulting about building a compliant call recording and transcription pipeline for your PHP contact centre.

Share this article:
0 views

Ready to Transform Your Business Communications?

Get a free consultation with our VoIP experts and discover how we can help you save costs, improve efficiency, and scale your business.

Comments (0)

Join the discussion and share your thoughts (AI-moderated for quality)

Protected by AI moderation

Be the first to comment

No comments yet. Share your thoughts below.