How to use openai.audio.speech.create in node.js

The specs say that the return value is “The audio file content.” and examples show “mp3.arrayBuffer()” and “mp3.stream_to_file()”.

Can the documentation be updated to explain exactly what is returned from the speech.create() mthod?

1 Like

Isn’t the docs just implying it returns the raw bytes the content of an audio file?

Looks like this one worked.

const mp3 = Buffer.from(await response.arrayBuffer());

So the client.audio.speech.create method seems to return a Node “response” object, and we get the raw bytes using the .arrayBuffer() method.

Docs need to be updated, please, in Nodejs almost all elements on the response interface are undefined.

PLEASE OPENAI, update audio docs :frowning:

Check the reference page

  const mp3 = await openai.audio.speech.create({
    model: "tts-1",
    voice: "nova",
    input: "Today is a wonderful day to build something people love!",
    speed: 1.0,
  });

  const buffer = Buffer.from(await mp3.arrayBuffer());
  await fs.promises.writeFile(filename, buffer);

Ensure that there is “await” in that last line. That is a promise.