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.
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.
npm install @deepgram/sdk
yarn add @deepgram/sdk
const { Deepgram } = require("@deepgram/sdk");
const deepgram = new Deepgram(DEEPGRAM_API_KEY);
const fileSource = { url: URL_OF_FILE };
const response = await deepgram.transcription.preRecorded(fileSource, {
punctuate: true,
});
const streamSource = {
stream: fs.createReadStream("/path/to/file"),
mimetype: MIMETYPE_OF_FILE,
};
const response = await deepgram.transcription.preRecorded(streamSource, {
punctuate: true,
});
See an example real time project at https://github.com/deepgram-devs/node-live-example, or visit this Getting Started guide
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
Returns all projects accessible by the API key.
deepgram.projects
.list()
.then((response) => {
console.log("list", response);
})
.catch((err) => {
console.log("err", err);
});
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 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 a project.
deepgram.projects
.delete("84b227ad-dfac-4096-82f6-f7397006050b")
.then((response) => {
console.log("delete", response);
})
.catch((err) => {
console.log("err", err);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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);
});
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
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.
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:
- Open an issue on this repository
- Tweet at us! We're @DeepgramAI on Twitter
Check out the Developer Documentation at https://developers.deepgram.com/