1

I receive a buffer through an input:

const fileData = Buffer.concat(chunks);

I then send this input into OpenAI's Whisper which excepts a file

const resp = await openai.createTranscription( //@ts-ignore
   fileData,
   "whisper-1",
);

This doesn't work so first I save the file to the disk

fs.writeFileSync("input.wav", fileData);

Then I read it again in the response function

const resp = await openai.createTranscription( //@ts-ignore
   createReadStream("input.wav"),
   "whisper-1",
);

This works but I don't want to save the file the disk every time I run the function. Is there a way to convert a buffer into the same NodeJS stream or achieve something with the same final output without saving it to the disk?

1 Answers1

0
async function uploadFile(data:Buffer) {
const file = new Blob([data], { type: 'audio/ogg' });
const formData = new FormData();

formData.append("audio_file", file);

const headers = {
    Accept: 'application/json'
}

return fetch(`http://whisper:9000/asr?method=openai-whisper&task=transcribe&encode=true&output=json&language=ru`, { headers:headers, method:"POST", body:formData });

}

KoIIIeY
  • 533
  • 1
  • 7
  • 26