Pre-Recorded Audio Transcription

An overview of the Deepgram JavaScript SDK and Deepgram speech-to-text pre-recorded.

The Deepgram JavaScript SDK now works in both server and browser environments. A proxy configuration is required for browser environments (see the section below).

Installing the SDK

TypeScript
1# Install the Deepgram JS SDK
2# https://github.com/deepgram/deepgram-js-sdk
3
4npm install @deepgram/sdk

Initializing the SDK

TypeScript
1import { createClient } from "@deepgram/sdk";
2
3const deepgram = createClient("DEEPGRAM_API_KEY");

Transcribing a file by URL

Any public audio or video file can be used.

TypeScript
1const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
2 {
3 url: "https://dpgr.am/spacewalk.wav"
4 },
5 {
6 model: "nova-3"
7 }
8);

Transcribing a file buffer

Any ArrayBufferLike can be sent as the body. This includes file buffers from Node’s fs.readFile/fs.readFileSync, or a Blob.arrayBuffer() in a browser client.

TypeScript
1const { result, error } = await deepgram.listen.prerecorded.transcribeFile(
2 fs.readFileSync("./examples/spacewalk.wav"),
3 {
4 model: "nova-3",
5 }
6);

Transcribing a file stream

Any ReadStream can be sent as the body. This includes a stream from Node’s fs.createReadStream.

TypeScript
1const { result, error } = await deepgram.listen.prerecorded.transcribeFile(
2 fs.createReadStream("./examples/spacewalk.wav"),
3 {
4 model: "nova-3",
5 }
6);

Pre-recorded Transcription Options

Transcription options are provided as an object to our transcription functions. Each of these parameters are found as unique features on the Pre-Recorded API reference.

Helper Functions

In the latest SDK version, caption formatting has been has been published as a standalone package and built into the SDK. You can use an import statement to invoke caption functionality from the stand alone caption package.

Formatting as WebVTT

JavaScript
1import { createClient } from "@deepgram/sdk";
2import { webvtt } from "@deepgram/captions";
3// - or -
4// import { createClient, webvtt } from "@deepgram/sdk";
5
6const deepgram = createClient("DEEPGRAM_API_KEY");
7
8const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
9 {
10 url: "https://dpgr.am/spacewalk.wav"
11 },
12 {
13 model: "nova-3",
14 }
15);
16
17if (error) {
18 console.error(error);
19}
20
21const captions = webvtt(result);

Formatting as SRT

JavaScript
1import { createClient } from "@deepgram/sdk";
2import { srt } from "@deepgram/captions";
3// - or -
4// import { createClient, webvtt } from "@deepgram/sdk";
5
6const deepgram = createClient("DEEPGRAM_API_KEY");
7
8const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
9 {
10 url: "https://dpgr.am/spacewalk.wav"
11 },
12 {
13 model: "nova-3",
14 }
15);
16
17if (error) {
18 console.error(error);
19}
20
21const captions = srt(result);
Built with