help icon indicating copy to clipboard operation
help copied to clipboard

How to convert a buffer to a readable file in NodeJS

Open vinaysruban opened this issue 1 year ago • 1 comments

Details

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?

Node.js version

Not applicable.

Example code

No response

Operating system

Windows 10

Scope

My problem is with the code itself, not the outcome.

Module and version

Not applicable.

vinaysruban avatar Mar 20 '23 09:03 vinaysruban