Web Dev CodyW
Convex Communityβ€’2y agoβ€’
7 replies
Web Dev Cody

Help with Openai Whipser

so in convex, I'm trying to generate some text to speech using this sdk

async function generateAudio(text: string) {
  const mp3 = await openai.audio.speech.create({
    model: "tts-1",
    voice: "onyx",
    input: text,
  });
  const buffer = Buffer.from(await mp3.arrayBuffer());
  return buffer;
}


and then I'm trying to pass that to this type of function

export async function getTranscripts(audio: Buffer) {
  try {
    const transcription = await openai.audio.transcriptions.create({
      file: audio,
      model: "whisper-1",
      timestamp_granularities: ["word"],
      response_format: "verbose_json",
    });
    return transcription;
  } finally {
    // No cleanup needed as we didn't create any files
  }
}
Was this page helpful?