Article·Tutorials·Jul 25, 2022

Transcribing Radio Broadcasts With Node.js

Kevin Lewis
By Kevin Lewis
PublishedJul 25, 2022
UpdatedJun 13, 2024

There are so many uses for Deepgram's live transcription service - from captioning meetings and events to creating home assistance and supporting call center operators by picking up on keywords.

Today, you'll use the Deepgram JavaScript SDK to provide live transcriptions to live radio broadcasts and store spoken words in a file that can then be further analyzed.

Before You Start

You will need a Deepgram API Key - get one here.

Create a new directory, open it on a code editor, and navigate to it in your terminal. Initialize a new Node.js project and install this project's dependencies:

cross-fetch is used to make HTTP requests more straightforward in your Node.js projects. Alternatives include axiosgot, and httpie - use whatever works for you or the default http library in Node.js, which requires no dependencies.

Create an index.js file and open it in your code editor. Initialize the project dependencies:

Create a Deepgram Live Transcription Session

Initialize the Deepgram JavaScript SDK, and create a new live transcription session:

Two features are used in this session - punctuation and tier. Read more about Deepgram features such as redaction, diarization, and language.

Fetch Real-Time Data from Radio Stations

Make sure you have a direct audio stream for the radio station. A good way of testing this is to open the URL in a browser - you should see just the built-in browser audio player without an accompanying web page.

Here are a few URLs for you to try:

If you use the French channel, be sure to add language: fr to your Deepgram session options.

Run your code with node index.js, leave it running for a couple of seconds, and stop it with ctrl+c. You should see a bunch of buffers logged to your console.

This is what you want to see - these buffers of audio data can be sent directly to Deepgram.

Transcribe the Radio Station

Replace console.log(data) with the following to send the buffers to Deepgram if the connection is still open:

At the bottom of index.js, below all other code, add this code to listen for returned transcripts:

Rerun your code, and you should see transcripts in your terminal.

Save New Transcripts to a File

To save these transcripts to a file, you must first create a write stream and then write content to it. At the top of your file, just below your require statements, create the stream:

The a flag will open the file specifically for appending new data. If it does not exist, it will be automatically created.

Replace console.log(transcript) with the following:

This will add the new transcript to the end of the existing file, ensuring there is a space between each item.

Run your code again, wait a few seconds, and then stop it. Take a look at the new output.txt file, and you should see a big block of text which can then be stored in a database for compliance or further analysis.

In Summary

The full code is here:

If you have any questions, please feel free to reach out to us over email (devrel@deepgram.com) or via Twitter (@DeepgramDevs).

If you have any feedback about this post, or anything else around Deepgram, we'd love to hear from you. Please let us know in our GitHub discussions .

Unlock language AI at scale with an API call.

Get conversational intelligence with transcription and understanding on the world's best speech AI platform.