Anil Magar
CCConvex Community
•Created by Anil Magar on 4/25/2024 in #support-community
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 ?4 replies