35 lines
1018 B
JavaScript
35 lines
1018 B
JavaScript
const fs = require('fs');
|
|
const dotenv = require('dotenv');
|
|
|
|
dotenv.config();
|
|
|
|
async function test() {
|
|
const formData = new FormData();
|
|
formData.append('model', 'saaras:v4');
|
|
formData.append('with_timestamps', 'true');
|
|
|
|
// Create a 1 sec silent wav file
|
|
const buf = Buffer.alloc(44 + 16000 * 2);
|
|
buf.write('RIFF', 0); buf.writeUInt32LE(36 + 16000 * 2, 4);
|
|
buf.write('WAVE', 8); buf.write('fmt ', 12);
|
|
buf.writeUInt32LE(16, 16);
|
|
buf.writeUInt16LE(1, 20); buf.writeUInt16LE(1, 22);
|
|
buf.writeUInt32LE(16000, 24); buf.writeUInt32LE(32000, 28);
|
|
buf.writeUInt16LE(2, 32); buf.writeUInt16LE(16, 34);
|
|
buf.write('data', 36); buf.writeUInt32LE(16000 * 2, 40);
|
|
|
|
formData.append('file', new Blob([buf], { type: 'audio/wav' }), 'test.wav');
|
|
|
|
const res = await fetch('https://api.sarvam.ai/speech-to-text', {
|
|
method: 'POST',
|
|
headers: {
|
|
'api-subscription-key': process.env.SARVAM_API_KEY
|
|
},
|
|
body: formData
|
|
});
|
|
|
|
console.log(res.status);
|
|
console.log(await res.text());
|
|
}
|
|
test();
|