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,
});
navigator.mediaDevices.getUserMedia({ audio: true }).then((stream) => {
const mediaRecorder = new MediaRecorder(stream, {
mimeType: 'audio/webm',
});
const deepgramSocket = deepgram.transcription.live({ punctuate: true });
deepgramSocket.addListener('open', () => {
mediaRecorder.addEventListener('dataavailable', async (event) => {
if (event.data.size > 0 && deepgramSocket.readyState == 1) {
deepgramSocket.send(event.data)
}
})
mediaRecorder.start(1000)
});
deepgramSocket.addListener("transcriptReceived", (received) => {
const transcript = received.channel.alternatives[0].transcript;
if (transcript && received.is_final) {
console.log(transcript);
}
});
});
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 @DeepgramDevs on Twitter
Check out the Developer Documentation at https://developers.deepgram.com/