openai-node
openai-node copied to clipboard
createTranscription() doesn't work as expected in NodeJS
Describe the bug
Hi!
I tried to follow the documentation when I was writing a transcription script using NodeJS. And I wanted to get a response in .srt format. But it returns an error. I tried to use the argument response_format as well as responseFormat(). But that didn't work. Also, there is only one way to communicate with OpenAI API:
const resp = await openai.createTranscription(
fs.createReadStream('audio.mp3'),
"whisper-1"
);
But anyway, it doesn't work if I would like to specify the output file format.
To Reproduce
- Run the function (one of them)
- Get
Required parameter model was null or undefinederror
Code snippets
async function getTranscription() {
const resp = await openai.createTranscription(
fs.createReadStream('audio.mp3'),
"whisper-1",
responseFormat('srt')
);
console.log(resp.data);
}
const options = {
file: fs.createReadStream('audio.mp3'),
model: "whisper-1",
response_format: "srt"
};
async function getTranscription() {
const resp = await openai.createTranscription(options);
console.log(resp.data);
}
### OS
macOS
### Node version
Node v.16.13.0
### Library version
openai v.3.2.1
See https://github.com/openai/openai-node/issues/77#issuecomment-1455247809, it describes a solution to this problem.
@DeveloperRyan thank you! But where is it showing a solution for the issue with the output file format (.srt not .json)?
@DeveloperRyan thank you! But where is it showing a solution for the issue with the output file format (.srt not .json)?
Sorry -- looks like I misdirected you. I missed you mentioning the srt part specifically, and assumed you were just having issues with actually getting the response. Will keep my eye opened for any solutions and update if I see any.
Having the same issue whenever I try to add a parameter other than file & model.
Indeed, after reading Github README and API documentation you would expect that method createTranscription accepts an object but it accepts only raw parameters.
https://platform.openai.com/docs/api-reference/audio/create?lang=node
Especially the "Parameters" example is a bit misleading because it is formatted as object.

The following code works:
const fs = require('fs');
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: '<OPENAI API KEY>',
});
const openai = new OpenAIApi(configuration);
async function run() {
const resp = await openai.createTranscription(
fs.createReadStream("sample-ja.mp3"),
"whisper-1",
undefined,
"srt",
0.1,
"ja",
);
return resp;
}
But object format would be easier to use because now you need some time to check the order of the arguments and insert undefined value where needed.
P.S. It really looks like a bug, because function createCompletion in README accepts an object.
same error, and The above method didn't work 🤔 please help
https://platform.openai.com/docs/api-reference/audio/create?lang=node
@KirillSapranov thanks! But that was one of the first things I made and checked. It doesn't work either.
I am using "openai": "3.2.1",, maybe you tried with a different version. please, let me know
So I did figure it out. The trick is - yes, use raw params. Even formData.append was acting up for me. So just pass the audio stream, model, optional prompt, temperature etc in a particular order (you can check the exact order by going through the wrapper index).
Not sure if they fixed this in any of the recent updates.
@KirillSapranov thanks! But that was one of the first things I made and checked. It doesn't work either.
I am using
"openai": "3.2.1",, maybe you tried with a different version. please, let me know
Did you try the code in my comment (replace file name and language with yours)? If yes, what error do you get?
I'm also using openai 3.2.1 on Windows WSL 2 (Ubuntu).
@KirillSapranov thanks! But that was one of the first things I made and checked. It doesn't work either. I am using
"openai": "3.2.1",, maybe you tried with a different version. please, let me knowDid you try the code in my comment (replace file name and language with yours)? If yes, what error do you get?
I'm also using openai 3.2.1 on Windows WSL 2 (Ubuntu).
@KirillSapranov I re-installed openai package and now it is working! Thanks a lot!