Actually when I replicate a voice using the gemini API it returns a voice_id which can be used like shown in the following code block:
import base64
from google import genai
from pathlib import Path
here = Path(__file__).parent
client = genai.Client()
def clone():
with open(here / "audios" / "source.wav", "rb") as f:
source_b64 = base64.b64encode(f.read()).decode("utf-8")
with open(here / "audios" / "consent.wav", "rb") as f:
consent_b64 = base64.b64encode(f.read()).decode("utf-8")
# Create a persistent replicated voice (store=True)
replicated_voice = client.voices.create(
store=True,
voice={
"model": "gemini-3.8-flash-tts",
"type": "replicated",
"display_name": "Custom Replicated Speaker",
"replicated": {
"source_audio": {
"mime_type": "audio/wav",
"data": source_b64,
},
"consent_audio": {
"mime_type": "audio/wav",
"data": consent_b64,
},
},
},
)
print(f"Created voice ID: {replicated_voice.id}")
print(f"{replicated_voice=}")
return replicated_voice.id
def synth(voice_id: str):
interaction = client.interactions.create(
model="gemini-3.8-flash-tts",
input=[{
"type": "user_input",
"content": [{
"type": "text",
"text": (
"Hello world"
),
"annotations": [{
"type": "speech_metadata",
"style": "warm and conversational",
}],
}],
}],
response_format={"type": "audio"},
generation_config={
"speech_config": [
{"voice": voice_id},
]
},
)
with open(here / "38-flash.wav", "wb") as f:
f.write(base64.b64decode(interaction.output_audio.data))
if __name__ == "__main__":
voice_id = clone()
synth(voice_id)
But when I try to pass the replicated voice id to the Gemini TTS plugin (in the parameter voice_name), I get the following error
livekit.agents ._exceptions.APIStatusError: message='gemini tts: client error', status_code=400, retryable=False, body={
"error": {
"code": 400,
"message": "No matching speaker voice found for name: <replicated_voice_id> and language: "
"status": "INVALID_ARGUMENT"
}
}
I also tried with the voice name used (in this case “Custom Replicated Speaker”) and its returning the same error
Here’s the official documentation about replication: https://ai.google.dev/gemini-api/docs/voice-replication#audio_and_consent_requirements