xtekky/gpt4free · error · ValueError

Unsupported audio format: {audio_format}

Error message

Unsupported audio format: {audio_format}

What it means

Thrown by transcribe_audio() (g4f/integration/markitdown/_transcribe_audio.py) when audio_format is not one of the hardcoded accepted values: wav, aiff, flac (passed through directly) or mp3, mp4, webm (converted to wav via pydub). Any other string — including case variants and close relatives like ogg or m4a — is rejected.

Source

Thrown at g4f/integration/markitdown/_transcribe_audio.py:45

    if _dependency_exc_info is not None:
        raise MissingDependencyException(
            "Speech transcription requires installing MarkItdown with the [audio-transcription] optional dependencies. E.g., `pip install markitdown[audio-transcription]` or `pip install markitdown[all]`"
        ) from _dependency_exc_info[
            1
        ].with_traceback(  # type: ignore[union-attr]
            _dependency_exc_info[2]
        )

    if audio_format in ["wav", "aiff", "flac"]:
        audio_source = file_stream
    elif audio_format in ["mp3", "mp4", "webm"]:
        audio_segment = pydub.AudioSegment.from_file(file_stream, format=audio_format)

        audio_source = io.BytesIO()
        audio_segment.export(audio_source, format="wav")
        audio_source.seek(0)
    else:
        raise ValueError(f"Unsupported audio format: {audio_format}")

    recognizer = sr.Recognizer()
    with sr.AudioFile(audio_source) as source:
        audio = recognizer.record(source)
        if language is None:
            language = "en-US"
        try:
            transcript = recognizer.recognize_faster_whisper(
                audio, language=language.split("-")[0]
            ).strip()
        except ImportError:
            transcript = recognizer.recognize_google(audio, language=language).strip()
        return "[No speech detected]" if transcript == "" else transcript.strip()

View on GitHub (pinned to 973504e177)

Solutions

  1. Lowercase and strip parameters before calling: audio_format = fmt.lower().split(';')[0].split('/')[0].
  2. Transcode unsupported containers to wav or mp3 first (pydub.AudioSegment.from_file(...).export(fmt='wav')).
  3. For MediaRecorder output use 'webm' (or 'mp4' on Safari), which are both accepted.

Example fix

// before
transcribe_audio(stream, audio_format=mime_subtype)  # e.g. 'ogg'

// after
fmt = mime_subtype.lower()
if fmt not in ("wav", "aiff", "flac", "mp3", "mp4", "webm"):
    audio = pydub.AudioSegment.from_file(stream).export(format="wav")
    fmt = "wav"
    stream = audio
transcribe_audio(stream, audio_format=fmt)
Defensive patterns

Strategy: validation

Validate before calling

ACCEPTED = {"wav", "aiff", "flac", "mp3", "mp4", "webm"}

def acceptable_format(fmt: str) -> bool:
    return fmt.lower() in ACCEPTED

Prevention

When it happens

Trigger: transcribe_audio(f, audio_format='ogg'); audio_format='WAV' (uppercase fails the exact-match list); 'm4a' or 'opus' files forwarded from a browser MediaRecorder that records audio/webm;codecs=opus with the codec suffix left in the format string.

Common situations: Browser uploads where the client reports 'audio/ogg; codecs=opus' and the code passes the whole subtype; uppercase formats from MIME tables; AAC/M4A voice notes from iPhones.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/edc471c7c531bea1. Report an issue: GitHub.