import fs from "fs"; import OpenAI from "openai"; import prompt from "./prompt.md"; import { prisma } from "@/lib/prisma"; const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY, baseURL: process.env.OPENAI_API_BASE_URL, }); async function transcriptAudio(audio: Buffer | string) { if (typeof audio === "string") { audio = fs.readFileSync(audio); } const base64Audio = Buffer.from(audio).toString("base64"); const response = await client.chat.completions.create({ model: "gemini-2.5-flash-lite", messages: [ { role: "user", content: [ { type: "text", text: prompt, }, { type: "input_audio", input_audio: { data: base64Audio, format: "wav", }, }, ], }, ], }); console.log(response.choices[0].message.content); } async function transcriptAweme(awemeId: string) { const aweme = await prisma.video.findUnique({ where: { aweme_id: awemeId }, }); if (!aweme) { throw new Error("Aweme not found or aweme is not a video post"); } }