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).

Initializing the SDK

import { createClient } from "@deepgram/sdk";

const deepgram = createClient("DEEPGRAM_API_KEY");

Transcribing a file by URL

Any public audio or video file can be used.

const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
  {
    url: "https://dpgr.am/spacewalk.wav"
  },
  {
    model: "nova-2"
  }
);

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.

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

Transcribing a file stream

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

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

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

import { createClient } from "@deepgram/sdk";
import { webvtt } from "@deepgram/captions";
// - or -
// import { createClient, webvtt } from "@deepgram/sdk";

const deepgram = createClient("DEEPGRAM_API_KEY");

const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
  {
    url: "https://dpgr.am/spacewalk.wav"
  },
  {
    model: "nova-2",
  }
);

if (error) {
  console.error(error);
}

const captions = webvtt(result);

Formatting as SRT

import { createClient } from "@deepgram/sdk";
import { srt } from "@deepgram/captions";
// - or -
// import { createClient, webvtt } from "@deepgram/sdk";

const deepgram = createClient("DEEPGRAM_API_KEY");

const { result, error } = await deepgram.listen.prerecorded.transcribeUrl(
  {
    url: "https://dpgr.am/spacewalk.wav"
  },
  {
    model: "nova-2",
  }
);

if (error) {
  console.error(error);
}

const captions = srt(result);