Skip to content

Official JavaScript SDK for Deepgram's automated speech recognition APIs.

License

Notifications You must be signed in to change notification settings

jkroll-deepgram/deepgram-node-sdk

 
 

Repository files navigation

Deepgram Node.js SDK

CI npm (scoped) Contributor Covenant

Official Node.js SDK for Deepgram's automated speech recognition APIs.

This SDK only supports hosted usage of api.deepgram.com.

To access the API you will need a Deepgram account. Sign up for free at signup.

Documentation

Full documentation of the Node.js SDK can be found on the Deepgram Developer Portal.

You can learn more about the full Deepgram API at https://developers.deepgram.com.

Installation

With NPM

npm install @deepgram/sdk

With Yarn

yarn add @deepgram/sdk

Constructor

const { Deepgram } = require("@deepgram/sdk");

const deepgram = new Deepgram(DEEPGRAM_API_KEY);

Examples

Transcription

Pre-recorded

Remote Files

const fileSource = { url: URL_OF_FILE };

const response = await deepgram.transcription.preRecorded(fileSource, {
  punctuate: true,
});

Local Files

const streamSource = {
  stream: fs.createReadStream("/path/to/file"),
  mimetype: MIMETYPE_OF_FILE,
};

const response = await deepgram.transcription.preRecorded(streamSource, {
  punctuate: true,
});

Transcribe Audio in Real-Time

See an example real time project at https://github.com/deepgram-devs/node-live-example, or visit this Getting Started guide

Usage

listRequests

Retrieves all requests associated with the provided project_id based on the provided options.

deepgram.usage
  .listRequests("84b227ad-dfac-4096-82f6-f7397006050b", {
    start: "2022-07-01",
    end: "2022-07-28",
  })
  .then((response) => {
    console.log("Usage: ", response);
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

getRequest

Retrieves a specific request associated with the provided project_id.

deepgram.usage
  .getRequest(
    // projectId
    "84b227ad-dfac-4096-82f6-f7397006050b",
    // requestId
    "f12cc224-282b-4de4-90f1-651d5fdf04f1"
  )
  .then((response) => {
    fs.writeFileSync(
      `usage.json`,
      JSON.stringify(response),
      () => `Wrote json`
    );
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

getUsage

Retrieves usage associated with the provided project_id based on the provided options.

deepgram.usage
  .getUsage("84b227ad-dfac-4096-82f6-f7397006050b", {
    punctuate: true,
    diarize: true
  })
  .then((response) => {
    console.log("Usage: ", response);
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

getFields

Retrieves features used by the provided project_id based on the provided options.

deepgram.usage
  .getFields("84b227ad-dfac-4096-82f6-f7397006050b", {
    start: "2022-07-01",
    end: "2022-07-28",
  })
  .then((response) => {
    console.log("Usage: ", response);
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

Scopes

get

Retrieves scopes of the specified member in the specified project.

deepgram.scopes
  .get(
    "84b227ad-dfac-4096-82f6-f7397006050b",
    "f12cc224-282b-4de4-90f1-651d5fdf04f1"
  )
  .then((response) => {
    fs.writeFileSync(
      `scope.json`,
      JSON.stringify(response),
      () => `Wrote json`
    );
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

update

Updates the scope for the specified member in the specified project.

deepgram.scopes
  .update(
    "84b227ad-dfac-4096-82f6-f7397006050b",
    "f12cc224-282b-4de4-90f1-651d5fdf04f1",
    "member:read"
  )
  .then((response) => {
    console.log({response})
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

Projects

list

Returns all projects accessible by the API key.

deepgram.projects
  .list()
  .then((response) => {
    console.log("list", response);
  })
  .catch((err) => {
    console.log("err", err);
  });

get

Retrieves a specific project based on the provided project_id.

deepgram.projects
  .get("84b227ad-dfac-4096-82f6-f7397006050b")
  .then((response) => {
    console.log("list", response);
  })
  .catch((err) => {
    console.log("err", err);
  });

update

Update a project.

deepgram.projects
  .update(
    { project_id: "84b227ad-dfac-4096-82f6-f7397006050b" },
    {
      name: "A new name",
    }
  )
  .then((response) => {
    console.log("list", response);
  })
  .catch((err) => {
    console.log("err", err);
  });

delete

Delete a project.

deepgram.projects
  .delete("84b227ad-dfac-4096-82f6-f7397006050b")
  .then((response) => {
    console.log("delete", response);
  })
  .catch((err) => {
    console.log("err", err);
  });

Members

listMembers

Retrieves account objects for all of the accounts in the specified project.

deepgram.members
  .listMembers("84b227ad-dfac-4096-82f6-f7397006050b")
  .then((response) => {
    console.log("Members: ", response);
  })
  .catch((err) => {
    console.log("Members ERROR: ", err);
  });

deleteMembers

Removes member account for specified member_id.

 deepgram.members
  .removeMember(
    "84b227ad-dfac-4096-82f6-f7397006050b",
    "f12cc224-282b-4de4-90f1-651d5fdf04f1"
  )
  .then((response) => {
    console.log("Member DELETED: ", response);
  })
  .catch((err) => {
    console.log("Member DELETED ERROR: ", err);
  });

Keys

list

Retrieves all keys associated with the provided project_id.

deepgram.keys
  .list("84b227ad-dfac-4096-82f6-f7397006050b")
  .then((res) => {
    console.log({ res });
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

get

Retrieves a specific key associated with the provided project_id.

deepgram.keys
  .get(
    "84b227ad-dfac-4096-82f6-f7397006050b",
    "f12cc224-282b-4de4-90f1-651d5fdf04f1"
    )
  .then((res) => {
    console.log({ res });
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

create

Creates an API key with the provided scopes.

deepgram.keys
  .create(
    "84b227ad-dfac-4096-82f6-f7397006050b",
     "Temporary key",
    ["usage"],
    {
      timeToLive: 5000,
    }
  )
  .then((res) => {
    console.log({ res });
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

delete

Deletes a specific key associated with the provided project_id.

deepgram.keys
  .delete(
    "84b227ad-dfac-4096-82f6-f7397006050b",
    "f12cc224-282b-4de4-90f1-651d5fdf04f1"
  )
  .then((response) => {
    console.log("KEY DELTED: ", response);
  })
  .catch((err) => {
    console.log("KEY DELETED ERROR: ", err);
  });

Invitations

list

Retrieves all invitations associated with the provided project_id.

deepgram.invitations
  .list("84b227ad-dfac-4096-82f6-f7397006050b")
  .then((res) => {
    console.log({ res });
  })
  .catch((err) => {
    console.log("ERROR: ", err);
  });

send

Sends an invitation to the provided email address.

deepgram.invitation
  .send("84b227ad-dfac-4096-82f6-f7397006050b", {
    email: "[email protected]",
    scope: "member",
  })
  .then((response) => {
    console.log("Invitation sent: ", response);
  })
  .catch((err) => {
    console.log("Invitation ERROR: ", err);
  });

leave

Removes the authenticated user from the project.

deepgram.invitation
  .leave("84b227ad-dfac-4096-82f6-f7397006050b")
  .then((response) => {
    console.log({response});
  })
  .catch((err) => {
    console.log("Invitation leave ERROR: ", err);
  });

delete

Removes the specified invitation from the project.

deepgram.invitation
  .delete("84b227ad-dfac-4096-82f6-f7397006050b", "[email protected]")
  .then((response) => {
    console.log({response});
  })
  .catch((err) => {
    console.log("Invitation delete ERROR: ", err);
  });

Billing

listBalances

Retrieves the list of balance info for the specified project.

deepgram.billing
  .listBalances("84b227ad-dfac-4096-82f6-f7397006050b")
  .then((response) => {
    console.log({response});
  })
  .catch((err) => {
    console.log("Billing listBalances ERROR: ", err);
  });

getBalance

Retrieves the balance info for the specified project and balance_id.

deepgram.billing
  .getBalance("84b227ad-dfac-4096-82f6-f7397006050b", "21b98377-657e-471a-b75e-299fb99ec2c3")
  .then((response) => {
    console.log({response});
  })
  .catch((err) => {
    console.log("Billing getBalance ERROR: ", err);
  });

Samples

To run the sample code, first run the following in your terminal:

npm install
npm build

Then update the config object located at the top of the index.js file in the sample folder.

const config = {
  deepgramApiKey: "YOUR_DEEPGRAM_API_KEY",
  urlToFile:
    "https://static.deepgram.com/examples/Bueller-Life-moves-pretty-fast.wav",
};

Finally, run the sample code using the following command in your terminal:

node sample/index.js

The sample demonstrates the following uses:

  • Transcribing a prerecorded file
  • Retrieving usage for a project
  • Getting a project
  • Creating an API key
  • Deleting an API key

Development and Contributing

Interested in contributing? We ❤️ pull requests!

To make sure our community is safe for all, be sure to review and agree to our Code of Conduct. Then see the Contribution guidelines for more information.

Getting Help

We love to hear from you so if you have questions, comments or find a bug in the project, let us know! You can either:

Further Reading

Check out the Developer Documentation at https://developers.deepgram.com/

About

Official JavaScript SDK for Deepgram's automated speech recognition APIs.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 97.8%
  • Dockerfile 1.7%
  • JavaScript 0.5%