vercel/ai · error · InvalidArgumentError

The Gemini Live translation API only supports 16kHz 16-bit P

Error message

The Gemini Live translation API only supports 16kHz 16-bit PCM input audio.

What it means

validateGoogleSpeechTranslationInputAudioFormat enforces that audio fed to the Gemini Live translation API is 16-bit PCM at 16 kHz. Any other inputAudioFormat — a different container type, or a PCM sample rate other than 16000 — throws this InvalidArgumentError before the WebSocket session starts. The Live translation endpoint performs no resampling or transcoding on your behalf.

Source

Thrown at packages/google/src/speech-translation/google-speech-translation-model.ts:606

        targetLanguageCode: targetLanguage,
        ...(providerOptions?.echoTargetLanguage != null
          ? { echoTargetLanguage: providerOptions.echoTargetLanguage }
          : {}),
      },
    },
    inputAudioTranscription: {},
    outputAudioTranscription: {},
  };
}

function validateGoogleSpeechTranslationInputAudioFormat(
  inputAudioFormat: SpeechTranslationModelV4StreamOptions['inputAudioFormat'],
) {
  if (
    inputAudioFormat.type !== 'audio/pcm' ||
    (inputAudioFormat.rate != null && inputAudioFormat.rate !== 16000)
  ) {
    throw new InvalidArgumentError({
      argument: 'inputAudioFormat',
      message:
        'The Gemini Live translation API only supports 16kHz 16-bit PCM input audio.',
    });
  }
}

View on GitHub (pinned to 69428b1f8b)

Solutions

  1. Resample the audio to 16 kHz mono 16-bit PCM before streaming (e.g. AudioContext at 16000 sampleRate, or sox/ffmpeg server-side).
  2. Set inputAudioFormat: { type: 'audio/pcm', rate: 16000 } explicitly in the stream options.
  3. If you need other formats, transcode first — the API will not accept them.

Example fix

// before
await model.doStream({ inputAudioFormat: { type: 'audio/pcm', rate: 48000 }, ... });
// after
await model.doStream({ inputAudioFormat: { type: 'audio/pcm', rate: 16000 }, ... });
// and resample source audio to 16 kHz before streaming
Defensive patterns

Strategy: validation

Validate before calling

const fmt = options.inputAudioFormat;
if (fmt.type !== 'audio/pcm' || (fmt.rate != null && fmt.rate !== 16000)) {
  throw new Error('Resample audio to 16 kHz 16-bit PCM before streaming translation');
}

Type guard

function isPcm16k(
  f: SpeechTranslationModelV4StreamOptions['inputAudioFormat'],
): boolean {
  return f.type === 'audio/pcm' && (f.rate == null || f.rate === 16000);
}

Prevention

When it happens

Trigger: Passing inputAudioFormat with type other than 'audio/pcm' (e.g. 'audio/wav', 'audio/mp3') or type 'audio/pcm' with rate set to anything other than 16000 (e.g. 44100, 48000, 8000).

Common situations: Streaming microphone audio captured at 44.1/48 kHz without resampling; feeding compressed files instead of raw PCM; copying inputAudioFormat options from a different transcription provider that accepts arbitrary rates.

Related errors


AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30). Data as JSON: /api/errors/8a09dcf03a6a2ed7. Report an issue: GitHub.