For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Ask AIPlaygroundLoginFree API Key
HomeAPI ReferenceVoice AgentSpeech-to-TextText-to-SpeechIntelligenceSelf-Hosted Deployments
HomeAPI ReferenceVoice AgentSpeech-to-TextText-to-SpeechIntelligenceSelf-Hosted Deployments
    • Getting Started with Speech to Text
  • Pre-Recorded Audio
    • Getting Started
    • Feature Overview
    • Template Apps
      • Automatically Generating WebVTT & SRT Captions
      • Automatically Transcribe and Summarize Phone Calls
      • Getting Started with Deepgram Whisper Cloud
      • Generating and Saving Transcripts From the Terminal
      • Using Callbacks to Return Transcripts to Your Server
      • When Callback Is Not Received
      • When To Use Multichannel and Diarization
      • When To Use Keywords and Search
  • Streaming Audio
    • Compare Flux to Nova-3
  • Models and Languages
    • Models & Languages Overview
    • Languages Support
    • Language Detection
    • Multilingual Codeswitching
    • Model Options
    • Version
  • Formatting
    • Speaker Diarization
    • Dictation
    • Filler Words
    • Measurements
    • Numerals
    • Paragraphs
    • Profanity Filtering
    • Punctuation
    • Redaction
    • Smart Formatting
    • Supported Entity Types
    • Utterances
    • Utterance Split
  • Custom Vocabulary
    • Find and Replace
    • Keyterm Prompting
    • Keywords
    • Search
  • Media Input Settings
    • Channels
    • Encoding
    • Multichannel
    • Sample Rate
  • Results Processing
    • Understanding Word Confidence Scores
    • STT Callback
    • STT Tagging
    • Extra Metadata
  • Migrating
    • Migrating From Amazon Web Services (AWS) Transcribe to Deepgram
    • Migrating From Google Speech-to-Text (STT) to Deepgram
    • Migrating From OpenAI Whisper to Deepgram
    • Migrating from AssemblyAI Speech-to-Text to Deepgram
LogoLogo
Ask AIPlaygroundLoginFree API Key
On this page
  • Before You Start
  • Create a Deepgram Account
  • Create a Deepgram API Key
  • Create a Twilio Account
  • Have Access to Two Phones
  • Setting Up Twilio
  • Create a Service
  • Add Dependencies
  • Add Environment Variables
  • Recording and Forwarding Inbound Calls
  • Configure Your Twilio Number
  • Transcribing and Summarizing Calls
  • Transcribe the Call
  • Summarize the Call
  • Sending Summary Messages
  • Send the Summary via SMS
  • Testing Your Implementation
  • Full Sample Code
Pre-Recorded AudioTips and Tricks

Automatically Transcribe and Summarize Phone Calls

Learn how to use Twilio Functions and Deepgram's Summarization feature to transcribe and summarize phone calls before providing call participants with a phone call summary via SMS.
Was this page helpful?
Previous

Getting Started with Deepgram Whisper Cloud

Deepgram Whisper Cloud is a fully managed API that gives you access to Deepgram’s version of OpenAI’s Whisper model.

Next
Built with

One use for the Deepgram API is to transcribe calls between a caller and an agent. When paired with Twilio, a cloud communication platform that lets developers integrate a number of communication technologies into their applications, Deepgram’s API can be used to streamline your workflow by providing bite-sized versions of call recordings.

In this guide, you’ll learn how to use Twilio Functions and Deepgram’s Summarization feature to send phone call summaries via SMS once a conversation has ended. Using Twilio, you will build a phone number that forwards callers to your agent and begins recording. When the call is complete, Deepgram will provide both a transcript and summary of the call. Finally, the transcript and summary will be sent to both the caller and agent via SMS.

If you need reference material or you’d rather not follow along with this guide, we provide a full version of the sample code after the tutorial.

Before You Start

Before you run the code, you’ll need to do a few things.

Create a Deepgram Account

Before you can use Deepgram, you’ll need to create a Deepgram account. Signup is free and includes $200 in free credit and access to all of Deepgram’s features!

Create a Deepgram API Key

Before you start, you’ll need to follow the steps in the Make Your First API Request guide to obtain a Deepgram API key, and configure your environment if you are choosing to use a Deepgram SDK.

Create a Twilio Account

Before you can use Twilio, you’ll need to sign up for a Twilio account. Once signed up, make sure you have a phone number with SMS and Voice capabilities set up in your account.

Have Access to Two Phones

To test your project, you’ll need access to two phones—one to make a call and one to receive a call.

Setting Up Twilio

To use Twilio, you will need to create a new service, add the Deepgram SDK as a dependency, and add the appropriate environment variables.

Create a Service

Create a new service, which can contain multiple Twilio Functions and assets related to a single project.

  1. Log in to the Twilio Console, and navigate to Developer Tools > Functions & Assets.
  2. Create a new service. It’s important that you create a new service rather than a standalone function.

Add Dependencies

Inside your new service, add the Deepgram SDK as a dependency:

  1. Locate the Dependencies section.
  2. Add @deepgram/sdk. To get the latest version, omit the version number.

Add Environment Variables

Inside your new service, add your Deepgram API Key and your agent phone number as environment variables:

  1. Locate the Environment Variables section.

  2. Add the following variables:

    Variable nameVariable content
    DEEPGRAM_KEYValue of your Deepgram API Key generated in your Deepgram Console
    FORWARDING_NUMBERValue of your agent phone number in E.164 formatting (example: +14155552671)

Recording and Forwarding Inbound Calls

Create a Twilio function that receives incoming call data and forwards it to your agent while recording it:

  1. Rename the /welcome function to /inbound.

  2. Replace the entire file with the following code:

    JavaScript
    1exports.handler = function (context, event, callback) {
    2 let twiml = new Twilio.twiml.VoiceResponse();
    3 const dial = twiml.dial({
    4 record: "record-from-answer-dual",
    5 recordingStatusCallback: "/recordings",
    6 });
    7 dial.number(process.env.FORWARDING_NUMBER);
    8 return callback(null, twiml);
    9};

When the call is completed, call data will be sent to /recordings, which you will create later in this guide.

  1. Save the function, and select Deploy All. Once deployed, this function is ready to be used.

Configure Your Twilio Number

Now that you have created a function to receive incoming calls, apply it to your Twilio number:

  1. Navigate to your Twilio number settings.
  2. Under A Call Comes In, select Function.
  3. Under Service, select your service.
  4. Under Function Path, select /inbound.

When a call comes in, use a Function. Default service with the /inbound function path.

Transcribing and Summarizing Calls

Now that your Twilio number is configured to record the phone call, you can use Deepgram to transcribe and summarize it.

Transcribe the Call

When a call is received, use Deepgram to transcribe it:

  1. Create a new Twilio function named /transcribe.

  2. Replace the boilerplate code with the following code:

    JavaScript
    1import { DeepgramClient } from "@deepgram/sdk";
    2const deepgram = new DeepgramClient({ apiKey: process.env.DEEPGRAM_API_KEY });
    3
    4exports.handler = async function (context, event, callback) {
    5 const { RecordingUrl, CallSid } = event;
    6 const twilioClient = context.getTwilioClient();
    7 const { from: caller, to: twilioNumber } = await twilioClient.calls(CallSid).fetch();
    8
    9 // Further code here
    10
    11 return callback(null, true);
    12};

This code uses the CallSid to look up the call to find additional call information. Once done, the caller’s phone number will be available in a variable called caller, and the number they placed the call to will be available in a variable called twilioNumber.

  1. Generate a transcription of the call using Deepgram’s Node.js SDK:

    JavaScript
    1const result = await deepgram.listen.v1.media.transcribeUrl({
    2 url: RecordingUrl,
    3 punctuate: true,
    4 tier: "enhanced",
    5 summarize: "v2",
    6});

Summarize the Call

From Deepgram’s transcription, isolate the summary:

JavaScript
1const summary = result.results.summary.short;

Sending Summary Messages

Now that you have a summary of the call, you can send it to both the caller and the agent.

Send the Summary via SMS

Finally, you can send Deepgram’s summary via SMS:

JavaScript
1for (let number of [process.env.FORWARD_NUMBER, caller]) {
2 await twilioClient.messages.create({
3 body: summary,
4 to: number,
5 from: twilioNumber,
6 });
7}

Save both files again, and deploy all functions in your service.

Testing Your Implementation

To test your implementation, call your Twilio number, pick it up on your “agent device”, speak, and hang up. You should receive a summary message via SMS a few seconds later.

Full Sample Code

In case you need it for reference, we provide the full sample code used in this tutorial below:

JavaScript
1// /inbound
2exports.handler = function (context, event, callback) {
3 let twiml = new Twilio.twiml.VoiceResponse();
4 const dial = twiml.dial({
5 record: "record-from-answer-dual",
6 recordingStatusCallback: "/transcribe",
7 });
8 dial.number(process.env.FORWARDING_NUMBER);
9 return callback(null, twiml);
10};
11
12// /transcribe
13import { DeepgramClient } from "@deepgram/sdk";
14const deepgram = new DeepgramClient({ apiKey: process.env.DEEPGRAM_API_KEY });
15
16exports.handler = async function (context, event, callback) {
17 const { RecordingUrl, CallSid } = event;
18 const twilioClient = context.getTwilioClient();
19 const { from: caller, to: twilioNumber } = await twilioClient.calls(CallSid).fetch();
20
21 const result = await deepgram.listen.v1.media.transcribeUrl({
22 url: RecordingUrl,
23 punctuate: true,
24 tier: "enhanced",
25 summarize: "v2",
26 });
27
28 const summary = result.results.summary.short;
29
30 for (let number of [process.env.FORWARDING_NUMBER, caller]) {
31 await twilioClient.messages.create({
32 body: summary,
33 to: number,
34 from: twilioNumber,
35 });
36 }
37
38 return callback(null, true);
39};