import{d as t,n as o,c as e}from"../../nitro/nitro.mjs";import r from"openai";import i from"fs/promises";import a from"path";import s from"os";import"node:http";import"node:https";import"node:crypto";import"stream";import"events";import"http";import"crypto";import"buffer";import"zlib";import"https";import"net";import"tls";import"url";import"node:events";import"node:buffer";import"node:fs";import"node:path";import"chokidar";import"@anthropic-ai/claude-code";import"fs";import"readline";import"node:url";const n=new r({apiKey:process.env.OPENAI_API_KEY||""}),p=t(async t=>{try{const r=await o(t);if(!r||0===r.length)throw e({statusCode:400,statusMessage:"No audio file provided"});const p=r.find(t=>"audio"===t.name);if(!p||!p.data)throw e({statusCode:400,statusMessage:"Audio file not found in form data"});if(!process.env.OPENAI_API_KEY)throw e({statusCode:500,statusMessage:"OpenAI API key not configured"});const m=s.tmpdir(),d=a.join(m,`whisper-${Date.now()}.webm`);try{await i.writeFile(d,p.data);const t=await i.readFile(d),o=new File([t],"audio.webm",{type:"audio/webm"}),e=await n.audio.transcriptions.create({file:o,model:"whisper-1",language:"en"});return await i.unlink(d).catch(()=>{}),{success:!0,text:e.text}}catch(t){throw await i.unlink(d).catch(()=>{}),e({statusCode:500,statusMessage:t.message||"Failed to transcribe audio"})}}catch(t){if(t.statusCode)throw t;throw e({statusCode:500,statusMessage:t.message||"Internal server error"})}});export{p as default};
//# sourceMappingURL=whisper.post.mjs.map
