deepgram / deepgram-js-sdk

Official JavaScript SDK for Deepgram's automated speech recognition APIs.
https://developers.deepgram.com
MIT License
127 stars 45 forks source link

Deepgram giving error on local audio #222

Closed rajooadv closed 5 months ago

rajooadv commented 5 months ago

I'm using deepgram api and when I use deepgram audio file url https://static.deepgram.com/examples/deep-learning-podcast-clip.wav then it give output.vvt but If I use local file then it give error

    at D:\NodeJS\deepgram\server\node_modules\@deepgram\sdk\dist\main\packages\AbstractRestfulClient.js:37:28
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  __dgError: true,
  status: 400
}```
Code (Node JS) : 
``` require('dotenv').config();

const fs = require('fs');
const path = require('path');
const { createClient, webvtt } = require("@deepgram/sdk");

const deepgram = createClient(process.env.DP_API);
console.log(process.env.DP_API);

const audioFilePath = path.join(__dirname, 'wav.wav');

deepgram.listen.prerecorded.transcribeUrl(
    {
        url: audioFilePath,
    },
    { smart_format: true, utterances: true }
).then(({ result, error }) => {
    if (error) {
        console.error("Transcription error:", error);
        return;
    }

    const captions = webvtt(result);

    // Writing captions to a WebVTT file
    fs.writeFile("output.vtt", captions, (err) => {
        if (err) {
            console.error("Error writing captions to file:", err);
        } else {
            console.log("Captions written to output.vtt successfully!");
        }
    });
}).catch(err => {
    console.error("Error during transcription:", err);
});