audio file generated using openai text to speech and uploaded to convex storage is not playing
I have created the audio file using openai text to speech in next js project . everything works fine even the file is uploaded to storage. but when I get the url and try to play it or open the url and try to download it . the url doesnot work . can somebody help me with this .
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 ?2 Replies
I would debug this one layer at a time by seeing what the value is at each step. You can look at the files uploaded in your Convex dashboard and download the file and see if something is wrong, or if it is being saved as the wrong type or something else is the matter.
The problem is I could not download the file as well.
but I will try the way you mentioned
will let you know if I will get further issues.