audio file generated using openai text to speech and uploaded to convex storage is not playing
here is the code below
openAI.ts
"use server";
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
export const generatePodcastVoice = async () => {
const response = await openai.audio.speech.create({
model: "tts-1",
voice: "alloy",
input:
"Today is a wonderful day to build something people love!. Just because you are a character doesn't mean you have character.",
});
return response;
};
then I am uploading it using convex api from fronend.
here is the function
const generatePodcast = async () => {
setIsGenerating(true);
try {
const response = await generatePodcastVoice();
const buffer = Buffer.from(await response.arrayBuffer());
const blob = new Blob([buffer], { type: "audio/mpeg" });
console.log("blob", blob);
const file = new File([blob],
podcast-${uuidv4()}.mp3, {type: blob.type,
});
const uploaded = await startUpload([file]); // Pass an array of files
const storageId = (uploaded[0].response as any).storageId;
await storePodcastStorageId({ storageId });
setIsGenerating(false);
} catch (error) {
console.error(error);
}
};
is there anything wrong with my implements ?
