Google TTS Plugin Unsupported audio encoding error

When I try standard voice i don’t get this error. However I try gemini-flash-tts I have this error.

FAILED tests/agent/test_latency.py::test_gemini_tts_latency - livekit.agents._exceptions.APIStatusError: message=‘Unsupported audio encoding.’, status_code=400…

tts = google.TTS(
model_name="gemini-2.5-flash-tts",          # veya gemini-2.5-flash-tts
voice_name="Algenib",                        # veya Callirrhoe, Zephyr, Aoede vb.
)

@pytest.mark.asyncio

async def test_gemini_tts_latency():

metrics_data = \[\]

for i, text in enumerate(TEST_TEXTS):

    test_id = i + 1

    output_file = f"latency_test_output\_{test_id}.wav"

    wav = wave.open(output_file, "wb")

    wav.setnchannels(1)

    wav.setsampwidth(2)

    wav.setframerate(24000)

    first_chunk_time = None

    total_audio_bytes = 0

    time_to_first_audio = 0.0

    start_time = time.perf_counter()

    stream = tts.synthesize(text=text)

    async for audio in stream:

        if first_chunk_time is None:

            first_chunk_time = time.perf_counter()

            time_to_first_audio = first_chunk_time - start_time

        chunk_data = audio.frame.data.tobytes()

        total_audio_bytes += len(chunk_data)

        wav.writeframes(chunk_data)

    wav.close()

    end_time = time.perf_counter()

    total_time = end_time - start_time

    test_result = {

        "test_id": test_id,

        "text_length": len(text),

        "ttfa_seconds": round(time_to_first_audio, 4),

        "total_time_seconds": round(total_time, 4),

        "audio_size_bytes": total_audio_bytes,

        "file_path": output_file

    }

    metrics_data.append(test_result)

with open("latency_metrics.json", "w", encoding="utf-8") as f:

    json.dump(metrics_data, f, indent=4)


Hi, I think the Unsupported audio encoding message is misleading.

The root cause, I believe, is you are passing a model intended for Gemini TTS into Google Cloud TTS.

Gemini TTS:

Google Cloud TTS:

Thank you so much. At first, I tried using GEMINI API but It doesn’t support streaming capabilities and due to its speed. I transitioned into Google API. Is there any possible solution to use GEMINI Models with streaming capabilities?

BTW issue is due to audio encoding type. I changed audio encoding type to LINEAR16 and it works.
Google cloud support these models as you can see in the cloud documentation as well as dictated as parameters inside plugin

GeminiTTSModels = Literal\[

    *"gemini-3.1-flash-tts-preview"*,

    *"gemini-2.5-flash-tts"*,

    *"gemini-2.5-flash-lite-preview-tts"*,

    *"gemini-2.5-pro-tts"*,

\]