diff --git a/extensions/index.ts b/extensions/index.ts index f0436b0..7d77b59 100644 --- a/extensions/index.ts +++ b/extensions/index.ts @@ -560,7 +560,24 @@ async function transcribeWithEnne2(file: string): Promise { } try { - const b64 = fs.readFileSync(file).toString("base64"); + // Comprimi in MP3 per evitare HTTP 413 su audio lunghi (come il backend gemini) + let audioFile = file; + let audioFormat = "wav"; + if (file.toLowerCase().endsWith(".wav")) { + const mp3 = file.replace(/\.wav$/i, ".mp3"); + try { + await execFileAsync( + "ffmpeg", + ["-y", "-i", file, "-ac", "1", "-ar", "16000", "-c:a", "libmp3lame", "-q:a", "5", mp3], + { timeout: 60_000 }, + ); + audioFile = mp3; + audioFormat = "mp3"; + } catch { + /* fallback al WAV */ + } + } + const b64 = fs.readFileSync(audioFile).toString("base64"); const body = { model, messages: [ @@ -568,7 +585,7 @@ async function transcribeWithEnne2(file: string): Promise { role: "user", content: [ { type: "text", text: "Trascrivi fedelmente il parlato in questo audio. Rispondi solo con la trascrizione." }, - { type: "input_audio", input_audio: { data: b64, format: "wav" } }, + { type: "input_audio", input_audio: { data: b64, format: audioFormat } }, ], }, ],