#Pass Buffer
1 messages · Page 1 of 1 (latest)
Hi @steep pebble. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
To pass an audio buffer to the deepgram.listen.prerecorded.transcribeFile method in the Deepgram TypeScript SDK, you can use Node's fs.readFileSync function to read the audio file into a buffer. Here's an example:
const fs = require("fs");
const { createClient } = require("@deepgram/sdk");
const deepgram = createClient("YOUR_DEEPGRAM_API_KEY");
const transcribeAudio = async () => {
const { result, error } = await deepgram.listen.prerecorded.transcribeFile(
fs.readFileSync("./path_to_your_audio_file"),
{
model: "nova-2",
}
);
if (error) throw error;
console.dir(result, { depth: null });
};
transcribeAudio();
In this example, replace "./path_to_your_audio_file" with the path to your audio file and "YOUR_DEEPGRAM_API_KEY" with your actual Deepgram API key. The fs.readFileSync function reads the audio file and returns a buffer, which is then passed to the transcribeFile method.
Please note that the audio file should be in a format that Deepgram supports, such as WAV or MP3.
For more details, you can refer to the Deepgram documentation (https://developers.deepgram.com/docs/node-sdk-pre-recorded-transcription).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@steep pebble kapa.ai is still learning and improving, please let us know how it did by reacting below
@thick fjord no i do not have a local file i have buffer
Let me check the knowledge base for you. One moment! :books:
If you already have an audio buffer, you can pass it directly to the deepgram.listen.prerecorded.transcribeFile method in the Deepgram TypeScript SDK. Here's an example:
const { createClient } = require("@deepgram/sdk");
const deepgram = createClient("YOUR_DEEPGRAM_API_KEY");
const transcribeAudio = async (audioBuffer) => {
const { result, error } = await deepgram.listen.prerecorded.transcribeFile(
audioBuffer,
{
model: "nova-2",
}
);
if (error) throw error;
console.dir(result, { depth: null });
};
// Assuming `audioBuffer` is your Buffer containing audio data
transcribeAudio(audioBuffer);
In this example, replace "YOUR_DEEPGRAM_API_KEY" with your actual Deepgram API key. The audioBuffer is your Buffer containing audio data, which is then passed to the transcribeFile method.
Please note that the audio data in the buffer should be in a format that Deepgram supports, such as WAV or MP3.
For more details, you can refer to the Deepgram documentation (https://developers.deepgram.com/docs/node-sdk-pre-recorded-transcription).
Note: you can ask me a follow up question by @ mentioning me again :speech_balloon:
@steep pebble kapa.ai is still learning and improving, please let us know how it did by reacting below
@thick fjord Object literal may only specify known properties, and 'audioBuffer' does not exist in type 'FileSource'.ts(2353)
Let me check the knowledge base for you. One moment! :books:
I apologize for the confusion. The transcribeFile method in the Deepgram SDK expects a FileSource object, which should contain a buffer property, not audioBuffer.
Here's how you can pass the audio buffer:
const { createClient, FileSource } = require("@deepgram/sdk");
const deepgram = createClient("YOUR_DEEPGRAM_API_KEY");
const transcribeAudio = async (audioBuffer) => {
const payload: FileSource = {
"buffer": audioBuffer
}
const { result, error } = await deepgram.listen.prerecorded.v("1").transcribeFile(payload, options, timeout = 300);
if (error) throw error;
console.dir(result, { depth: null });
};
// Assuming `audioBuffer` is your Buffer containing audio data
transcribeAudio(audioBuffer);
In this example, replace "YOUR_DEEPGRAM_API_KEY" with your actual Deepgram API key. The audioBuffer is your Buffer containing audio data, which is then passed to the transcribeFile method as part of the FileSource object.
Please note that the audio data in the buffer should be in a format that Deepgram supports, such as WAV or MP3.