BerriAI/litellm · error · NvidiaRivaException

Could not decode audio for Riva STT. Convert your audio to w

Error message

Could not decode audio for Riva STT. Convert your audio to wav/flac/ogg before calling the API. Underlying error: {e}

What it means

Raised by litellm's Riva audio decoder when the audioread fallback itself throws while decoding the temp-file copy of the audio (after soundfile already failed). The underlying exception text is embedded. This is the generic 'format undecodable in this environment' terminal state for Riva STT input.

Source

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

            with audioread.audio_open(tmp_path) as src:
                source_rate = int(src.samplerate)
                channels: Final = int(src.channels)
                chunks: Final = []
                for buf in src:
                    chunks.append(np.frombuffer(buf, dtype=np.int16))
                if not chunks:
                    raise NvidiaRivaException(
                        status_code=400,
                        message="Audio decode produced no samples.",
                    )
                interleaved = np.concatenate(chunks).astype(np.float32) / 32768.0
                if channels > 1:
                    interleaved = interleaved.reshape(-1, channels)
                return cast("FloatArray", interleaved), source_rate
        except NvidiaRivaException:
            raise
        except Exception as e:
            raise NvidiaRivaException(
                status_code=400,
                message=(
                    "Could not decode audio for Riva STT. Convert your audio to "
                    f"wav/flac/ogg before calling the API. Underlying error: {e}"
                ),
            ) from e
    finally:
        try:
            os.unlink(tmp_path)
        except OSError:
            pass


def _resample(samples: "FloatArray", source_rate: int, target_rate: int) -> "FloatArray":
    """
    Resample mono float32 ``samples`` from ``source_rate`` to ``target_rate``.

    Prefers high-quality polyphase resampling when ``soxr`` or ``scipy`` is

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Install ffmpeg (audioread's primary backend) in the environment: apt-get install ffmpeg or equivalent.
  2. Convert the audio to wav/flac (16 kHz mono ideal) before calling transcription.
  3. Read the embedded 'Underlying error' to identify the failing backend and codec.
  4. Reinstall the stt-nvidia-riva extra to restore soundfile, which handles wav/flac/ogg natively.

Example fix

# before
litellm.transcription(model="nvidia_riva/riva_asr", file=open("clip.amr", "rb"))

# after: normalize format at ingest time
subprocess.run(["ffmpeg", "-i", "clip.amr", "-ar", "16000", "-ac", "1", "clip.wav"], check=True)
litellm.transcription(model="nvidia_riva/riva_asr", file=open("clip.wav", "rb"))
Defensive patterns

Strategy: fallback

Validate before calling

import shutil
if shutil.which("ffmpeg") is None:
    raise RuntimeError("ffmpeg not installed; Riva STT cannot decode non-wav audio")

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):
        wav_path = to_wav_16k_mono(f.name)  # subprocess ffmpeg fallback
        if wav_path:
            return litellm.transcription(model="nvidia_riva/riva_asr", file=open(wav_path, "rb"))
        raise
    raise

Prevention

When it happens

Trigger: Calling litellm.transcription() with nvidia_riva/* on audio whose format neither soundfile nor any audioread backend (ffmpeg, GStreamer, Core Audio) can decode — e.g. proprietary/proprietary-container codecs, DRM-protected files, or systems where ffmpeg is not installed so audioread has no backend.

Common situations: Minimal containers without ffmpeg where audioread falls back to nothing, exotic codecs (amr-nb, opus in ogg on old libs), or corrupted files that open but error mid-decode.

Related errors


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