help
help copied to clipboard
How to convert a buffer to a readable file in NodeJS
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.