{"record":{"id":"75db60b431d9e7fb","repo":"Mintplex-Labs/anything-llm","slug":"failed-to-transcribe-audio-75db60","errorCode":null,"errorMessage":"Failed to transcribe audio.","messagePattern":"Failed to transcribe audio\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/telegramBot/utils/media.js","lineNumber":61,"sourceCode":" * @param {string} [mimeType] - The MIME type of the audio (e.g., \"audio/ogg\")\n * @returns {Promise<string>}\n */\nasync function transcribeAudio(audioBuffer, mimeType = \"audio/ogg\") {\n  const fs = require(\"fs\");\n  const path = require(\"path\");\n  const { CollectorApi } = require(\"../../collectorApi\");\n  const { hotdirPath } = require(\"../../files\");\n\n  if (!fs.existsSync(hotdirPath)) fs.mkdirSync(hotdirPath, { recursive: true });\n\n  const ext = getExtensionFromMime(mimeType);\n  const filename = `telegram-voice-${Date.now()}${ext}`;\n  fs.writeFileSync(path.join(hotdirPath, filename), audioBuffer);\n\n  const collector = new CollectorApi();\n  const result = await collector.parseDocument(filename);\n  if (!result?.success || !result.documents?.length) {\n    throw new Error(result?.reason || \"Failed to transcribe audio.\");\n  }\n  return result.documents[0].pageContent;\n}\n\n/**\n * Parse a document buffer and extract its text content.\n * Writes the document to the collector hotdir and runs it through\n * the collector's parse pipeline.\n * @param {Buffer} documentBuffer\n * @param {string} originalFilename - The original filename with extension\n * @returns {Promise<{text: string, filename: string}>}\n */\nasync function documentToText(documentBuffer, originalFilename) {\n  const fs = require(\"fs\");\n  const path = require(\"path\");\n  const { CollectorApi } = require(\"../../collectorApi\");\n  const { hotdirPath } = require(\"../../files\");\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/telegramBot/utils/media.js#L43-L79","documentation":"Thrown by the Telegram voice-transcription path when collector.parseDocument(filename) returns no usable result (result.success falsy or no documents). The audio buffer was already written to the collector hotdir and parsed; failure here means transcription itself failed or returned empty. The thrown message uses result.reason if provided, else the generic string.","triggerScenarios":"A voice message in an unsupported audio codec; the collector's transcription backend (e.g. whisper) failing or misconfigured; an empty/corrupt audio buffer; the collector returning success=false with a reason.","commonSituations":"Whisper API key missing or invalid; collector container out of memory during transcription; audio file truncated during Telegram transfer; unsupported .oga variant the transcoder cannot decode.","solutions":["Check the collector logs for the underlying transcription error (often a model/API failure).","Verify the transcription backend config (API key, model name, endpoint) in collector settings.","Ensure ffmpeg/decoding deps are present in the collector image for the incoming codec.","Reply to the user asking them to resend as a common format (.mp3, .ogg) if the codec is exotic."],"exampleFix":"// before\nconst text = (await collector.parseDocument(filename)).documents[0].pageContent;\n\n// after\nconst result = await collector.parseDocument(filename);\nif (!result?.success || !result.documents?.length)\n  throw new Error(result?.reason || 'Failed to transcribe audio.');\nconst text = result.documents[0].pageContent;","handlingStrategy":"try-catch","validationCode":"const result = await collector.parseDocument(filename);\nif (!result?.success || !result.documents?.length)\n  throw new Error(result?.reason || 'Failed to transcribe audio.');","typeGuard":null,"tryCatchPattern":"try {\n  const text = await transcribeTelegramAudio(bot, fileId, mimeType);\n} catch (e) {\n  if (e.message === 'Failed to transcribe audio.')\n    return ctx.reply('Transcription failed; please resend the voice message.');\n  throw e;\n}","preventionTips":["Verify the transcription backend (API key, model) in collector settings.","Ensure ffmpeg/codec deps are present for the incoming audio format.","Log collector result.reason to diagnose specific failures."],"tags":["telegram","collector","transcription","audio"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}