From a453b87c6c0413f5593fd2ca4c2cbc84abe1777c Mon Sep 17 00:00:00 2001 From: Hanzo_dev <2002samudiojohan@gmail.com> Date: Wed, 1 Apr 2026 08:24:57 -0500 Subject: [PATCH] fix(backend): replace native File with toFile from openai SDK --- backend/lib/transcriptor.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/backend/lib/transcriptor.js b/backend/lib/transcriptor.js index 6a31bec..cbbd1fc 100644 --- a/backend/lib/transcriptor.js +++ b/backend/lib/transcriptor.js @@ -2,7 +2,7 @@ // TRANSCRIPTOR — OpenAI Whisper // Descarga el audio desde la URL y lo transcribe // ============================================================ -import OpenAI from 'openai' +import OpenAI, { toFile } from 'openai' const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY }) @@ -18,8 +18,9 @@ export async function transcribir(audioUrl, idioma = 'es') { throw new Error(`Error al descargar audio: ${audioResponse.status}`) } - const audioBuffer = await audioResponse.arrayBuffer() - const audioFile = new File([audioBuffer], 'audio.mp3', { type: 'audio/mpeg' }) + // En Vercel Serverless (Node < 20), Web API `File` no está disponible por defecto, + // y `arrayBuffer` consume mucha RAM. `toFile` soluciona ambos. + const audioFile = await toFile(audioResponse, 'audio.mp3', { type: 'audio/mpeg' }) const transcripcion = await openai.audio.transcriptions.create({ file: audioFile,