声音复刻
语音复制可让您使用 Gemini API 语音端点 (POST /v1beta/voices)。两者都 Gemini 3.8 Flash TTS (gemini-3.8-flash-tts)和 Gemini 3.8 Flash-Lite TTS (gemini-3.8-flash-lite-tts)支持语音复制。
复制、验证同意和试听复制声音的最快方法是使用交互式 语音复制 经验 Google AI Studio。您可以直接在浏览器中录制或上传参考和同意剪辑、预览语音并复制生成的结果 voice_... ID 直接添加到您的应用程序代码中。
有状态与无状态存储模式 #
通话时语音复制支持两种存储模式 voices.create (POST /v1beta/voices),默认启用有状态存储:
- 有状态存储(
store=True,推荐默认): Google 将您经过验证的语音配置文件存储在您的项目中,并返回一个轻量级、持久的voice_id(replicated_voice.id,例如voice_abc123...)。你可以通过这个voice_id跨请求并管理它voices.list(),voices.get(), 和voices.delete(). - 无状态客户端管理的密钥(
store=False,可选): 对于需要生物识别语音配置文件的服务器端零持久性的工作负载,设置store=False。 API 返回一个加密的、独立的voice_key(replicated_voice.key,开始于voicekey_...)您的应用程序在本地存储并直接在综合请求中传递。
| 存储方式 | 标识符 | 项目限额 | 保留(TTL) |
|---|---|---|---|
充满状态的声音 (store=True) | voice_... | 200 每个项目的声音 (在提示和复制的声音之间共享) | 1 上次使用年份 (滑动 expire_time;合成时重置) |
无状态语音键 (store=False) | voicekey_... | 客户管理 | 7 自创建之日起的天数 (固定 expire_time;更新使用 voices.create) |
- 配额等级和区域可用性: 语音复制需要 付费层级(1 或更高层级) Gemini API 项目(参见 速率限制);不需要单独的许可名单。全部都可以使用 支持的 Gemini API 区域,包括欧洲经济区 (EEA/EU)、英国和瑞士。
- 数据存储和删除(
store=True): 有状态存储会保留项目中提取的声音调节功能,而不是完整的原始声音调节功能consent_audio录音。呼唤voices.delete()立即从项目中删除存储的语音配置文件及其调节数据。 - 水印和出处: 所有合成的音频都包含难以察觉的 SynthID 音频水印。输入
source_audio和consent_audio必须是真实的人类录音;包含现有 SynthID 或 C2PA 水印的合成语音或音频在验证期间会被拒绝。
音频和同意要求 #
每个 CreateVoice 复制请求需要来自 同一个成人说话者 (推荐 24kHz 单声道 16 位 WAV):
- 参考音频(
source_audio): 10–30 的第二个剪辑,由您想要复制其声音的发言者发出的干净、自然的语音。 - 同意音频(
consent_audio): 同一发言者的录音清楚地背诵了其中一份文件中的强制同意声明 支持的语言 (例如,英语):> *“我是此语音的所有者,并且我同意 Google 使用此语音来
创建合成语音模型。”*
创建复制语音(有状态默认) #
使用 Google GenAI SDK (google-genai 2.25.0+ / @google/genai 2.24.0+) 或 REST API store=True 要在项目中创建并保存复制的语音配置文件:
import base64
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
with open("reference_speaker.wav", "rb") as f:
source_b64 = base64.b64encode(f.read()).decode("utf-8")
with open("speaker_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}")
import * as fs from "node:fs";
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } });
const sourceB64 = fs.readFileSync("reference_speaker.wav").toString("base64");
const consentB64 = fs.readFileSync("speaker_consent.wav").toString("base64");
// Create a persistent replicated voice (store: true)
const replicatedVoice = await ai.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: sourceB64,
},
consent_audio: {
mime_type: "audio/wav",
data: consentB64,
},
},
},
});
console.log(`Created voice ID: ${replicatedVoice.id}`);
SOURCE_B64=$(base64 -w 0 reference_speaker.wav)
CONSENT_B64=$(base64 -w 0 speaker_consent.wav)
curl "https://generativelanguage.googleapis.com/v1beta/voices" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d "{
\"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\"
}
}
}
}"
用复制的声音合成语音 #
通过返回的 id (voice_...)在您的综合请求中:
import base64
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
interaction = client.interactions.create(
model="gemini-3.8-flash-tts",
input=[{
"type": "user_input",
"content": [{
"type": "text",
"text": (
"Hello! This audio was synthesized using a replicated"
" speaker voice."
),
"annotations": [{
"type": "speech_metadata",
"style": "warm and conversational",
}],
}],
}],
response_format={"type": "audio"},
generation_config={
"speech_config": [
{"voice": replicated_voice.id},
]
},
)
with open("replicated_speech.wav", "wb") as f:
f.write(base64.b64decode(interaction.output_audio.data))
import * as fs from "node:fs";
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } });
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash-tts",
input: [{
type: "user_input",
content: [{
type: "text",
text: "Hello! This audio was synthesized using a replicated speaker voice.",
annotations: [{
type: "speech_metadata",
style: "warm and conversational",
}],
}],
}],
response_format: { type: "audio" },
generation_config: {
speech_config: [
{ voice: replicatedVoice.id },
],
},
});
if (interaction.output_audio?.data) {
fs.writeFileSync("replicated_speech.wav", Buffer.from(interaction.output_audio.data, "base64"));
}
curl "https://generativelanguage.googleapis.com/v1beta/interactions" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d '{
"model": "gemini-3.8-flash-tts",
"input": [{
"type": "user_input",
"content": [{
"type": "text",
"text": "Hello! This audio was synthesized using a replicated speaker voice.",
"annotations": [{
"type": "speech_metadata",
"style": "warm and conversational"
}]
}]
}],
"response_format": {"type": "audio"},
"generation_config": {
"speech_config": [
{"voice": "voice_YOUR_REPLICATED_VOICE_ID"}
]
}
}' | jq -r '[.steps[] | select(.type=="model_output") | .content[] | select(.type=="audio")] | last | .data' | base64 --decode > out.wav
管理存储的复制语音 #
创建时使用 store=True,您可以通过语音 API 列出、过滤、检查和删除复制的语音(请参阅 扩展语音库和过滤 对于所有过滤器参数):
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
# List stored replicated voices in your project
response = client.voices.list(type_=["replicated"])
for voice in response.voices or []:
print(voice.id, voice.display_name, voice.type)
# Retrieve a specific voice by ID
voice_details = client.voices.get(id=replicated_voice.id)
# Delete a stored replicated voice
client.voices.delete(id=replicated_voice.id)
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } });
// List stored replicated voices in your project
const response = await ai.voices.list({ type: ["replicated"] });
for (const voice of response.voices ?? []) {
console.log(voice.id, voice.display_name, voice.type);
}
// Retrieve a specific voice by ID
const voiceDetails = await ai.voices.get(replicatedVoice.id);
// Delete a stored replicated voice
await ai.voices.delete(replicatedVoice.id);
# List stored replicated voices in your project
curl -G "https://generativelanguage.googleapis.com/v1beta/voices" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
--data-urlencode "type=replicated"
# Retrieve a specific voice by ID
curl "https://generativelanguage.googleapis.com/v1beta/voices/voice_YOUR_REPLICATED_VOICE_ID" \
-H "x-goog-api-key: $GEMINI_API_KEY"
# Delete a stored replicated voice
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/voices/voice_YOUR_REPLICATED_VOICE_ID" \
-H "x-goog-api-key: $GEMINI_API_KEY"
选项:无状态客户端管理的语音键(store=False) #
如果您的应用程序需要语音配置文件的零服务器端持久性,请设置 store=False 创建复制声音时。 API 返回一个加密的 voice_key (replicated_voice.key,开始于 voicekey_...)绑定到您的项目及其 expire_time,您存储客户端并直接传递到任何地方 voice 身份证件被接受。
- 7 天密钥过期和续订: 无状态
voicekey_...token有一个固定的 7天 从创建开始的生命周期(replicated_voice.expire_time);在综合返回中使用过期密钥400 INVALID_ARGUMENT。要在过期之前或之后更新无状态密钥,请调用voices.create(POST /v1beta/voices)再次与store=False使用 相同存储source_audio和consent_audio录音—扬声器不需要录制新的音频。该服务重新验证录音并返回新的voicekey_...与新鲜的 7 天expire_time.
import base64
from google import genai
client = genai.Client(http_options={"api_version": "v1beta"})
with open("reference_speaker.wav", "rb") as f:
source_b64 = base64.b64encode(f.read()).decode("utf-8")
with open("speaker_consent.wav", "rb") as f:
consent_b64 = base64.b64encode(f.read()).decode("utf-8")
# Create a stateless client-managed voice key (store=False)
replicated_voice = client.voices.create(
store=False,
voice={
"model": "gemini-3.8-flash-tts",
"type": "replicated",
"replicated": {
"source_audio": {"mime_type": "audio/wav", "data": source_b64},
"consent_audio": {"mime_type": "audio/wav", "data": consent_b64},
},
},
)
# Pass replicated_voice.key ("voicekey_...") directly as the speaker voice
interaction = client.interactions.create(
model="gemini-3.8-flash-tts",
input=[{
"type": "user_input",
"content": [{
"type": "text",
"text": "Hello! This audio uses a stateless client-managed voice key.",
"annotations": [{
"type": "speech_metadata",
"style": "warm and conversational",
}],
}],
}],
response_format={"type": "audio"},
generation_config={
"speech_config": [
{"voice": replicated_voice.key},
]
},
)
import * as fs from "node:fs";
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({ httpOptions: { apiVersion: "v1beta" } });
const sourceB64 = fs.readFileSync("reference_speaker.wav").toString("base64");
const consentB64 = fs.readFileSync("speaker_consent.wav").toString("base64");
// Create a stateless client-managed voice key (store: false)
const replicatedVoice = await ai.voices.create({
store: false,
voice: {
model: "gemini-3.8-flash-tts",
type: "replicated",
replicated: {
source_audio: { mime_type: "audio/wav", data: sourceB64 },
consent_audio: { mime_type: "audio/wav", data: consentB64 },
},
},
});
// Pass replicatedVoice.key ("voicekey_...") directly as the speaker voice
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash-tts",
input: [{
type: "user_input",
content: [{
type: "text",
text: "Hello! This audio uses a stateless client-managed voice key.",
annotations: [{
type: "speech_metadata",
style: "warm and conversational",
}],
}],
}],
response_format: { type: "audio" },
generation_config: {
speech_config: [
{ voice: replicatedVoice.key },
],
},
});
SOURCE_B64=$(base64 -w 0 reference_speaker.wav)
CONSENT_B64=$(base64 -w 0 speaker_consent.wav)
curl "https://generativelanguage.googleapis.com/v1beta/voices" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
-H "Content-Type: application/json" \
-X POST \
-d "{
\"store\": false,
\"voice\": {
\"model\": \"gemini-3.8-flash-tts\",
\"type\": \"replicated\",
\"replicated\": {
\"source_audio\": {\"mime_type\": \"audio/wav\", \"data\": \"$SOURCE_B64\"},
\"consent_audio\": {\"mime_type\": \"audio/wav\", \"data\": \"$CONSENT_B64\"}
}
}
}"
按语言支持的同意短语 #
同意音频必须以 30 支持的语言区域之一清楚地叙述确切的声明:
| 语言 | 语言环境 (lang_id) | 同意声明原文(需逐字朗读) |
|---|---|---|
| 阿拉伯语 | ar-XA | أنا مالك هذا الصوت وأوافق على أن تستخدم Google هذا الصوت لإنشاء نموذج صوتي اصطناعي. |
| 孟加拉语 | bn-IN | আমি এই ভয়েসের মালিক এবং আমি একটি সিন্থেটিক ভয়েস মডেল তৈরি করতে এই ভয়েস ব্যবহার করে Google-এর সাথে সম্মতি দিচ্ছি। |
| 中文(简体) | zh-CN | 我是此声音的拥有者并授权谷歌使用此声音创建语音合成模型 |
| 荷兰语 | nl-NL | Ik ben de eigenaar van deze stem en ik geef Google toestemming om deze stem te gebruiken om een synthetisch stemmodel te maken. |
| 英语(美国) | en-US | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 英语(英国) | en-GB | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 英语(印度) | en-IN | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 英语(澳大利亚) | en-AU | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 法语(法国) | fr-FR | Je suis le propriétaire de cette voix et j'autorise Google à utiliser cette voix pour créer un modèle de voix synthétique. |
| 法语(加拿大) | fr-CA | Je suis le propriétaire de cette voix et j'autorise Google à utiliser cette voix pour créer un modèle de voix synthétique. |
| 德语 | de-DE | Ich bin der Eigentümer dieser Stimme und bin damit einverstanden, dass Google diese Stimme zur Erstellung eines synthetischen Stimmmodells verwendet. |
| 古吉拉特语 | gu-IN | હું આ વોઈસનો માલિક છું અને સિન્થેટિક વોઈસ મોડલ બનાવવા માટે આ વોઈસનો ઉપયોગ કરીને google ને હું સંમતિ આપું છું |
| 印地语 | hi-IN | मैं इस आवाज का मालिक हूं और मैं सिंथेटिक आवाज मॉडल बनाने के लिए Google को इस आवाज का उपयोग करने की सहमति देता हूं |
| 印度尼西亚语 | id-ID | Saya pemilik suara ini dan saya menyetujui Google menggunakan suara ini untuk membuat model suara sintetis. |
| 意大利语 | it-IT | Sono il proprietario di questa voce e acconsento che Google la utilizzi per creare un modello di voce sintetica. |
| 日语 | ja-JP | 私はこの音声の所有者であり、Googleがこの音声を使用して音声合成モデルを作成することを承認します。 |
| 卡纳达语 | kn-IN | ನಾನು ಈ ಧ್ವನಿಯ ಮಾಲಿಕ ಮತ್ತು ಸಂಶ್ಲೇಷಿತ ಧ್ವನಿ ಮಾದರಿಯನ್ನು ರಚಿಸಲು ಈ ಧ್ವನಿಯನ್ನು ಬಳಸಿಕೊಂಡುಗೂಗಲ್ ಗೆ ನಾನು ಸಮ್ಮತಿಸುತ್ತೇನೆ. |
| 韩语 | ko-KR | 나는 이 음성의 소유자이며 구글이 이 음성을 사용하여 음성 합성 모델을 생성할 것을 허용합니다. |
| 马拉雅拉姆语 | ml-IN | ഈ ശബ്ദത്തിന്റെ ഉടമ ഞാനാണ്, ഒരു സിന്തറ്റിക് വോയ്സ് മോഡൽ സൃഷ്ടിക്കാൻ ഈ ശബ്ദം ഉപയോഗിക്കുന്നതിന് ഞാൻ Google-ന് സമ്മതം നൽകുന്നു. |
| 马拉地语 | mr-IN | मी या आवाजाचा मालक आहे आणि सिंथेटिक व्हॉइस मॉडेल तयार करण्यासाठी हा आवाज वापरण्यासाठी मी Google ला संमती देतो |
| 波兰语 | pl-PL | Jestem właścicielem tego głosu i wyrażam zgodę na wykorzystanie go przez Google w celu utworzenia syntetycznego modelu głosu. |
| 葡萄牙语(巴西) | pt-BR | Eu sou o proprietário desta voz e autorizo o Google a usá-la para criar um modelo de voz sintética. |
| 俄语 | ru-RU | Я являюсь владельцем этого голоса и даю согласие Google на использование этого голоса для создания модели синтетического голоса. |
| 西班牙语(西班牙) | es-ES | Soy el propietario de esta voz y doy mi consentimiento para que Google la utilice para crear un modelo de voz sintética. |
| 西班牙语(美国) | es-US | Soy el propietario de esta voz y doy mi consentimiento para que Google la utilice para crear un modelo de voz sintética. |
| 泰米尔语 | ta-IN | நான் இந்த குரலின் உரிமையாளர் மற்றும் செயற்கை குரல் மாதிரியை உருவாக்க இந்த குரலை பயன்படுத்த குகல்க்கு நான் ஒப்புக்கொள்கிறேன். |
| 泰卢固语 | te-IN | నేను ఈ వాయిస్ యజమానిని మరియు సింతటిక్ వాయిస్ మోడల్ ని రూపొందించడానికి ఈ వాయిస్ ని ఉపయోగించడానికి googleకి నేను సమ్మతిస్తున్నాను. |
| 泰语 | th-TH | ฉันเป็นเจ้าของเสียงนี้ และฉันยินยอมให้ Google ใช้เสียงนี้เพื่อสร้างแบบจำลองเสียงสังเคราะห์ |
| 土耳其语 | tr-TR | Bu sesin sahibi benim ve Google'ın bu sesi kullanarak sentetik bir ses modeli oluşturmasına izin veriyorum. |
| 越南语 | vi-VN | Tôi là chủ sở hữu giọng nói này và tôi đồng ý cho Google sử dụng giọng nói này để tạo mô hình giọng nói tổng hợp. |
录制参考音频的最佳实践 #
- 在安静的环境下录音: 最大限度地减少室内回声、背景噪音、音乐和重叠的声音。
- 比赛记录条件: 记录两者
source_audio和consent_audio在同一声学设置下的同一麦克风上进行,因此扬声器验证检查可靠地成功。 - 转换为 24kHz 单声道 WAV: 为了获得最佳效果,请在编码前将输入音频重新采样为 24kHz 单声道 16 位 PCM WAV。