fix: graceful transcription fallback when ffmpeg unavailable (#155)

* fix: graceful transcription fallback when ffmpeg unavailable

When voice transcription fails (e.g., ffmpeg not installed), the agent
now receives informative error messages instead of silent failures.

Changes:
- transcribeAudio() returns TranscriptionResult with success/error/audioPath
- Tiered fallback: try format rename first, then ffmpeg, then fail gracefully
- Check ffmpeg availability once and cache result
- All channel adapters updated to show transcription errors to agent
- Agent can explain to user why transcription failed

Before:
  Agent sees: "[Voice message received]"
  Agent: "I received your voice message but there's no content..."

After:
  Agent sees: "[Voice message - transcription failed: Cannot transcribe .aac format. Install ffmpeg for audio conversion, or send in a supported format (mp3, ogg, wav, m4a). Audio saved to: /path/to/file.aac]"
  Agent: "I couldn't transcribe your voice message because ffmpeg isn't installed. You could type your message instead."

Fixes voice transcription on systems without ffmpeg.

Written by Cameron ◯ Letta Code

"Fail gracefully, inform clearly." - Error handling wisdom

* fix: handle undefined transcription errors better

* fix: correct API param for tool approval + workaround letta-client type bug
This commit is contained in:
Cameron
2026-02-04 19:31:50 -08:00
committed by GitHub
parent b4058f17ce
commit d6113cab66
7 changed files with 202 additions and 48 deletions

View File

@@ -161,13 +161,19 @@ Ask the bot owner to approve with:
const { transcribeAudio } = await import('../transcription/index.js');
const ext = audioAttachment.contentType?.split('/')[1] || 'mp3';
const transcript = await transcribeAudio(buffer, audioAttachment.name || `audio.${ext}`);
const result = await transcribeAudio(buffer, audioAttachment.name || `audio.${ext}`);
console.log(`[Discord] Transcribed audio: "${transcript.slice(0, 50)}..."`);
content = (content ? content + '\n' : '') + `[Voice message]: ${transcript}`;
if (result.success && result.text) {
console.log(`[Discord] Transcribed audio: "${result.text.slice(0, 50)}..."`);
content = (content ? content + '\n' : '') + `[Voice message]: ${result.text}`;
} else {
console.error(`[Discord] Transcription failed: ${result.error}`);
content = (content ? content + '\n' : '') + `[Voice message - transcription failed: ${result.error}]`;
}
}
} catch (error) {
console.error('[Discord] Error transcribing audio:', error);
content = (content ? content + '\n' : '') + `[Voice message - error: ${error instanceof Error ? error.message : 'unknown error'}]`;
}
}