Backend enne2: compressione MP3 per evitare HTTP 413 + sttBackend default gemini
This commit is contained in:
+19
-2
@@ -560,7 +560,24 @@ async function transcribeWithEnne2(file: string): Promise<TranscriptResult> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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 = {
|
const body = {
|
||||||
model,
|
model,
|
||||||
messages: [
|
messages: [
|
||||||
@@ -568,7 +585,7 @@ async function transcribeWithEnne2(file: string): Promise<TranscriptResult> {
|
|||||||
role: "user",
|
role: "user",
|
||||||
content: [
|
content: [
|
||||||
{ type: "text", text: "Trascrivi fedelmente il parlato in questo audio. Rispondi solo con la trascrizione." },
|
{ 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 } },
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user