deepgram / deepgram-js-sdk

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

Why does this basic example not work? #95

Closed BogdanMaier closed 1 year ago

BogdanMaier commented 1 year ago

I am trying to submit the demo video for transcription

Thought the param seems fine and I am using the correct protocol (https) the API request fails. Although that error is familiar to me form HTTP vs HTTPS clients usage that control does not exist from the params configuring deepgram.

Steps to reproduce

Checkout repo: https://github.com/BogdanMaier/deepgram-issue.git I contains the minimum code to run into the issue. Please update the the DEEPGRAM_API_SECRET with your value.

A side question one should use secret or key when submitting the data for transcription?

Expected behavior

I would expect the submission to work as expected and get the transcript

Please tell us about your environment

We want to make sure the problem isn't specific to your operating system or programming language.

Other information

ERROR: DG: TypeError [ERR_INVALID_PROTOCOL]: Protocol "https" not supported. Expected "https:"

m1ggy commented 1 year ago

having the same issue as well. 😕 I did a work around using this code from this resource. Hope it helps!

import https from "https";
....
 const options = {
                    method: "POST",
                    hostname: "api.deepgram.com",
                    port: null,
                    path: "/v1/listen",
                    headers: {
                        "content-type": "application/json",
                        Authorization: `Token ${process.env.DG_KEY}`
                    }
                };
                const request = https.request(options, response => {
                    const chunks = [];
                    response.on("data", function (chunk) {
                        chunks.push(chunk);
                    });
                    response.on("end", function () {
                        const body = Buffer.concat(chunks);
                        const r = JSON.parse(body.toString());
                        if (r.results && r.results.channels && r.results.channels.length) {
                            const transcript = r.results.channels[0].alternatives.map(alt => alt.transcript);
                            res.status(200).json({ transcript, success: true });
                        }
                    });
                    response.on("error", (e) => {
                        throw e;
                    });
                });
...
michaeljolley commented 1 year ago

Thanks for reporting @BogdanMaier and for confirming @m1ggy. PR #96 is incoming to fix the issue.