BerriAI/litellm · error · NvidiaRivaException

Could not decode audio for Riva STT. Install audio extras (`

Error message

Could not decode audio for Riva STT. Install audio extras (`pip install 'litellm[stt-nvidia-riva]'`) or convert your audio to wav/flac/ogg before calling the API. Underlying error: {sf_error}

What it means

Raised by litellm's Riva audio decoder when soundfile cannot decode the audio (unsupported format or soundfile missing) AND the audioread fallback is not installed. The message embeds the underlying soundfile error and instructs installing the stt-nvidia-riva extra or pre-converting to wav/flac/ogg.

Source

Thrown at litellm/llms/nvidia_riva/audio_transcription/audio_utils.py:115

    sf_error: Exception | None = None
    try:
        import soundfile as sf

        with io.BytesIO(file_bytes) as buf:
            data, source_rate = sf.read(buf, dtype="float32", always_2d=False)
        return cast("FloatArray", data), int(source_rate)
    except ImportError as e:
        sf_error = e
    except Exception as e:
        # soundfile raises RuntimeError / LibsndfileError for formats it
        # cannot decode (mp3 on older libsndfile, m4a, webm, ...).
        sf_error = e

    try:
        import audioread
    except ImportError as e:
        raise NvidiaRivaException(
            status_code=400,
            message=(
                "Could not decode audio for Riva STT. Install audio extras "
                f"(`pip install 'litellm[stt-nvidia-riva]'`) or convert your "
                f"audio to wav/flac/ogg before calling the API. "
                f"Underlying error: {sf_error}"
            ),
        ) from e

    # audioread backends (FFmpeg subprocess, GStreamer, Core Audio) require a
    # filesystem path, so spill the bytes to a temp file. mkstemp is portable
    # to Windows where re-opening a NamedTemporaryFile is not allowed.
    fd, tmp_path = tempfile.mkstemp(suffix=".audio")
    try:
        with os.fdopen(fd, "wb") as tmp_file:
            tmp_file.write(file_bytes)
        try:
            with audioread.audio_open(tmp_path) as src:

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. pip install 'litellm[stt-nvidia-riva]' (adds soundfile/audioread) and install system libsndfile/ffmpeg.
  2. Pre-convert audio to wav or flac with ffmpeg before calling transcription.
  3. If soundfile is installed but failing, update libsndfile (newer versions decode mp3).
  4. Check the embedded 'Underlying error' to see which decode path failed.

Example fix

# before
with open("voice-memo.m4a", "rb") as f:
    litellm.transcription(model="nvidia_riva/riva_asr", file=f)

# after: convert to wav first
import subprocess
subprocess.run(["ffmpeg", "-i", "voice-memo.m4a", "-ar", "16000", "-ac", "1", "memo.wav"], check=True)
with open("memo.wav", "rb") as f:
    litellm.transcription(model="nvidia_riva/riva_asr", file=f)
Defensive patterns

Strategy: fallback

Validate before calling

def can_decode_locally(path: str) -> bool:
    try:
        import soundfile as sf  # noqa: F401
        return True
    except ImportError:
        pass
    import shutil
    return shutil.which("ffmpeg") is not None

Try / catch

from litellm.exceptions import APIError
try:
    litellm.transcription(model="nvidia_riva/riva_asr", file=f)
except APIError as e:
    if "Could not decode audio" in str(e) and "Install audio extras" in str(e):
        # fallback: convert with ffmpeg then retry
        wav = convert_to_wav(f.name)
        litellm.transcription(model="nvidia_riva/riva_asr", file=open(wav, "rb"))
    else:
        raise

Prevention

When it happens

Trigger: Calling litellm.transcription() with nvidia_riva/* on an environment lacking the stt extras, feeding formats soundfile can't handle (m4a, webm, mp3 on older libsndfile) so decode falls through to the missing audioread fallback.

Common situations: Recording browser audio (webm/opus) or phone audio (m4a/amr) and sending it straight to Riva STT on a minimal install; CI environments without ffmpeg/libsndfile system libs.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/0baafcdfad437d6e. Report an issue: GitHub.