langgenius/dify · error · UnsupportedAudioTypeError

unsupported_audio_type

unsupported_audio_type

Error message

Audio type not allowed.

What it means

Raised by _transcribe_audio_to_text when AudioService raises UnsupportedAudioTypeServiceError — the uploaded audio's MIME type or extension is not in the allowed set for speech-to-text. Translated to UnsupportedAudioTypeError (HTTP 415, error_code 'unsupported_audio_type').

Source

Thrown at api/controllers/console/app/audio.py:159

            )
        else:
            response = AudioService.transcript_agent_asr(
                app_model=app_model,
                agent_soul=agent_soul,
                file=file,
                session=session,
                end_user=None,
            )
        return dump_response(AudioTranscriptResponse, response)
    except services.errors.app_model_config.AppModelConfigBrokenError:
        logger.exception("App model config broken.")
        raise AppUnavailableError()
    except NoAudioUploadedServiceError:
        raise NoAudioUploadedError()
    except AudioTooLargeServiceError as e:
        raise AudioTooLargeError(str(e))
    except UnsupportedAudioTypeServiceError:
        raise UnsupportedAudioTypeError()
    except ProviderNotSupportSpeechToTextServiceError:
        raise ProviderNotSupportSpeechToTextError()
    except SpeechToTextDisabledServiceError:
        raise SpeechToTextDisabledError()
    except ProviderTokenNotInitError as ex:
        raise ProviderNotInitializeError(ex.description)
    except QuotaExceededError:
        raise ProviderQuotaExceededError()
    except ModelCurrentlyNotSupportError:
        raise ProviderModelCurrentlyNotSupportError()
    except InvokeError as e:
        raise CompletionRequestError(e.description)
    except HTTPException:
        raise
    except ValueError:
        raise
    except Exception as e:
        logger.exception("Failed to transcribe audio to text")

View on GitHub (pinned to ef8544b173)

Solutions

  1. Convert the audio to MP3 before uploading (ffmpeg -i in.wav out.mp3).
  2. Set the correct Content-Type and filename extension on the multipart part.
  3. Configure the recorder to output an accepted container/codec.
  4. Check the provider's supported formats in the model provider settings.

Example fix

// before
form.append('file', wavBlob, 'message.wav');

// after: convert to mp3 client-side or server-side first
form.append('file', mp3Blob, 'message.mp3');
Defensive patterns

Strategy: validation

Validate before calling

const ALLOWED = ['audio/mpeg', 'audio/mp3'];
function assertAllowedAudio(file) {
  if (!ALLOWED.includes(file.type) && !/\.mp3$/i.test(file.name)) throw new Error('Only MP3 audio is supported');
  return file;
}

Type guard

const isAllowedAudio = (f) => ALLOWED.includes(f.type) || /\.mp3$/i.test(f.name);

Try / catch

try { await axios.post(`/apps/${id}/audio-to-text`, form); }
catch (e) { if (e.code === 'unsupported_audio_type') { /* convert to mp3 then retry */ } }

Prevention

When it happens

Trigger: Uploading a format the STT provider rejects: .wav, .m4a, .ogg, .flac when only .mp3 is supported (the OpenAPI doc describes the param as 'MP3 audio to transcribe'), or an unknown/ambiguous content type.

Common situations: Browser recorder producing webm/ogg; user attaching a voice memo in m4a; Content-Type header missing so the service cannot infer the format.

Related errors


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/0d85025c0dc1b354. Report an issue: GitHub.