Synchronous transcribe with audio retrieved from a URL
Below is an example node.js code that invokes synchronous POST /asr/transcribe Web API. It gets audio from the provided URL, transcribes it, and returns the transcription result.
USER_GENERATED_JWT_TOKEN should be replaced with a JWT token obtained as described here https://support.voicegain.ai/hc/en-us/articles/360028023691-JWT-Authentication (Note: the "Web API" setting shown in the screenshot is now called "API Security")
const https = require("https");
const jwt_Token = "USER_GENERATED_JWT_TOKEN"
const bearer = "Bearer" + " " + jwt_Token;
const post_data = JSON.stringify({
audio: {
source: {
fromUrl: {
url:
"https://f002.backblazeb2.com/file/voicegain-cdn/499632__iceofdoom__hello-is-anyone-out-there-curious-male-16kHz-mono.wav",
},
},
},
});
const options = {
hostname: "api.voicegain.ai",
path: "/v1/asr/transcribe",
method: "POST",
headers: {
Authorization: bearer,
"Content-Type": "application/json",
"Content-Length": post_data.length,
Accept: "application/json",
},
};
const req = https.request(options, (res) => {
console.log("statusCode:", res.statusCode);
console.log("headers:", res.headers);
res.on("data", (d) => {
process.stdout.write(d);
});
});
req.on("error", (err) => {
console.log("Error: " + err.message);
});
req.write(post_data);
req.end();
Comments
0 comments
Please sign in to leave a comment.