Back to Blog
Language How-Tos

How to Record and Transcribe a Phone Call in Twilio Using Node.js

Enable call recording in Twilio from Node.js and set up transcription webhooks to receive text versions of call recordings automatically.

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

This tutorial shows how to enable call recording and retrieve automatic transcriptions in Node.js using the Twilio REST API and TwiML Record verb. It targets developers building call logging systems, quality assurance tools, or transcript-based analytics who want Twilio to handle the audio capture and speech-to-text conversion. You will enable recording on an outbound call, set up a recording status callback webhook in Express, and access the transcription text once Twilio finishes processing the audio.

Prerequisites and Setup

Install the packages with npm install twilio express dotenv and expose your local Express server with npx ngrok http 3000. Twilio records calls server-side without any client-side setup; the audio is stored on Twilio's servers until you delete it or it expires after a default retention period. Configure a recordingStatusCallback URL 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.

npm install twilio express dotenv

# .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 client.calls.create() to enable recording and receive a notification when the audio is ready. The TwiML /voice route uses the record verb with transcribe: true and a transcribeCallback URL so Twilio both records and transcribes the caller's message. The recording callback webhook receives the RecordingSid, RecordingUrl, and RecordingDuration fields in the POST body. The transcription callback receives TranscriptionText and TranscriptionSid once the speech-to-text processing completes.

require('dotenv').config();
const express = require('express');
const twilio = require('twilio');

const app = express();
app.use(express.urlencoded({ extended: false }));

const client = twilio(
  process.env.TWILIO_ACCOUNT_SID,
  process.env.TWILIO_AUTH_TOKEN
);

app.post('/voice', (req, res) => {
  const twiml = new twilio.twiml.VoiceResponse();
  twiml.say({ voice: 'alice' },
    'This call is being recorded. Please leave your message after the tone.'
  );
  twiml.record({
    timeout: 10,
    transcribe: true,
    transcribeCallback: '/transcription',
  });
  twiml.say({ voice: 'alice' }, 'Thank you. Goodbye.');
  res.type('text/xml');
  res.send(twiml.toString());
});

app.post('/recording-status', (req, res) => {
  const sid      = req.body.RecordingSid      || '';
  const url      = req.body.RecordingUrl      || '';
  const duration = req.body.RecordingDuration || '';
  console.log('Recording ready:', sid, duration + 's', url);
  res.sendStatus(204);
});

app.post('/transcription', (req, res) => {
  const text = req.body.TranscriptionText || '';
  const sid  = req.body.TranscriptionSid  || '';
  console.log('Transcript [' + sid + ']:', text);
  res.sendStatus(204);
});

async function makeRecordedCall(to, twimlUrl, callbackUrl) {
  const call = await client.calls.create({
    to,
    from: process.env.TWILIO_PHONE_NUMBER,
    url: twimlUrl,
    record: true,
    recordingStatusCallback: callbackUrl,
  });
  console.log('Call SID:', call.sid);
  return call.sid;
}

app.listen(3000, () => console.log('Recording server on port 3000'));

Testing and Debugging

Start the server and ngrok, then call makeRecordedCall() with your phone number and the ngrok URLs. After the call ends, watch the terminal for the recording callback POST with 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 HTTPS ngrok address followed by /recording-status. Access recordings directly in the Twilio Console under Monitor, Recordings to verify the audio file exists before debugging the webhook flow.

Taking It Further

Download the recording MP3 by appending .mp3 to the RecordingUrl using Node.js https.get() and store it in S3 for long-term retention beyond Twilio's default storage period. Run the transcription text through keyword detection, sentiment analysis, or PII scanning using standard npm NLP packages. Build a compliance system that flags transcripts containing specific words and routes them to a quality assurance queue for human review. Delete recordings from Twilio after downloading by calling client.recordings(sid).remove() to reduce storage costs once you have your own copy in S3.

Talk to Telphi Consulting about building a compliant call recording and transcription pipeline for your Node.js 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.