Desain suara memungkinkan Anda membuat persona vokal persisten yang benar-benar baru dari deskripsi bahasa alami menggunakan endpoint Suara Gemini API (POST /v1beta/voices). Daripada terbatas pada suara bawaan atau merekam audio referensi, Anda dapat mendeskripsikan usia, timbre vokal, aksen, dan penyampaian dasar karakter, serta menerima ID voice_... yang dapat digunakan kembali dan disimpan ke project Anda.
Cara tercepat untuk mendesain, menguji, dan melakukan iterasi pada suara kustom adalah dengan studio Desain Suara interaktif di Google AI Studio. Anda dapat
membuat persona kustom dari perintah teks, mengujinya dengan skrip contoh, dan
menyalin ID voice_... yang dihasilkan langsung ke kode aplikasi Anda.
Gemini 3.8 Flash TTS
(gemini-3.8-flash-tts) dan
Gemini 3.8 Flash-Lite TTS
(gemini-3.8-flash-lite-tts) mendukung Desain suara.
Membuat suara yang didesain
Gunakan Google GenAI SDK (google-genai 2.25.0+ / @google/genai 2.24.0+) atau REST API
untuk membuat suara kustom dari deskripsi teks. Untuk suara "prompted", voices.create (CreateVoice) dan voices.get (GetVoice) menampilkan kolom sample_audio hanya output (mime_type: "audio/wav", data yang dienkode base64) sehingga Anda dapat langsung mencoba suara yang dihasilkan:
Python
import base64
from google import genai
client = genai.Client()
# 1. Design a custom voice persona from natural language
created_voice = client.voices.create(
store=True,
voice={
"model": "gemini-3.8-flash-tts",
"type": "prompted",
"display_name": "Warm British Astronomer",
"gender": "male",
"language_code": "en-GB",
"prompted": {
"input": (
"A warm, thoughtful astronomer in his late 60s with a gentle"
" British accent, speaking with quiet wonder."
)
},
},
)
print(f"Created voice ID: {created_voice.id}")
# Save the generated sample_audio preview (audio/wav) returned by CreateVoice
if created_voice.sample_audio and created_voice.sample_audio.data:
with open("voice_preview.wav", "wb") as f:
f.write(base64.b64decode(created_voice.sample_audio.data))
JavaScript
import * as fs from "node:fs";
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI();
// 1. Design a custom voice persona from natural language
const createdVoice = await ai.voices.create({
store: true,
voice: {
model: "gemini-3.8-flash-tts",
type: "prompted",
display_name: "Warm British Astronomer",
gender: "male",
language_code: "en-GB",
prompted: {
input:
"A warm, thoughtful astronomer in his late 60s with a gentle British accent, speaking with quiet wonder.",
},
},
});
console.log(`Created voice ID: ${createdVoice.id}`);
// Save the generated sample_audio preview (audio/wav) returned by CreateVoice
if (createdVoice.sample_audio?.data) {
fs.writeFileSync(
"voice_preview.wav",
Buffer.from(createdVoice.sample_audio.data, "base64")
);
}
REST
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": "prompted",
"display_name": "Warm British Astronomer",
"gender": "male",
"language_code": "en-GB",
"prompted": {
"input": "A warm, thoughtful astronomer in his late 60s with a gentle British accent, speaking with quiet wonder."
}
}
}' | tee created_voice.json | jq -r '.sample_audio.data' | base64 --decode > voice_preview.wav
Cara kerja desain Voice
- Membuat suara yang dipicu: Panggil
voices.create(POST /v1beta/voices) dengantype="prompted"danstore=True. - Menerima pratinjau
voice_iddansample_audiopersisten: API membuat identitas vokal, menyimpannya di project Anda, dan menampilkan ID permanen (misalnya,voice_abc123...) bersama dengansample_audio(mime_type: "audio/wav",databerenkode base64) yang berisi audio pratinjau yang dihasilkan untuk suara. - Sintesis ucapan: Teruskan
voice_iddi mana pun nama suara diterima dalam permintaan sintesis Anda.
Menyintesis ucapan dengan suara yang Anda rancang
Setelah membuat suara, teruskan id (voice_...) ke Interactions API untuk menghasilkan ucapan:
Python
import base64
from google import genai
client = genai.Client()
interaction = client.interactions.create(
model="gemini-3.8-flash-tts",
input=[{
"type": "user_input",
"content": [{
"type": "text",
"text": (
"Look out past the rings of Saturn. Those faint photons left"
" their source millions of years ago."
),
"annotations": [{
"type": "speech_metadata",
"style": "reflective and awe-inspired",
}],
}],
}],
response_format={"type": "audio"},
generation_config={
"speech_config": [
{"voice": created_voice.id},
]
},
)
with open("designed_voice.wav", "wb") as f:
f.write(base64.b64decode(interaction.output_audio.data))
JavaScript
import * as fs from "node:fs";
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI();
const interaction = await ai.interactions.create({
model: "gemini-3.8-flash-tts",
input: [{
type: "user_input",
content: [{
type: "text",
text: "Look out past the rings of Saturn. Those faint photons left their source millions of years ago.",
annotations: [{
type: "speech_metadata",
style: "reflective and awe-inspired",
}],
}],
}],
response_format: { type: "audio" },
generation_config: {
speech_config: [
{ voice: createdVoice.id },
],
},
});
fs.writeFileSync("designed_voice.wav", Buffer.from(interaction.output_audio.data, "base64"));
REST
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": "Look out past the rings of Saturn. Those faint photons left their source millions of years ago.",
"annotations": [{
"type": "speech_metadata",
"style": "reflective and awe-inspired"
}]
}]
}],
"response_format": {"type": "audio"},
"generation_config": {
"speech_config": [
{"voice": "voice_YOUR_DESIGNED_VOICE_ID"}
]
}
}'
Mengelola suara Anda
Anda dapat mencantumkan, memfilter, memeriksa, dan menghapus suara tersimpan Anda kapan saja menggunakan Voices API (lihat Library Suara yang Diperluas dan pemfilteran untuk semua parameter filter).
- Batas penyimpanan dan TTL: Suara stateful (
store=True, dibagikan di seluruh suara yang diminta dan direplikasi) memiliki batas 200 suara per project dan TTL 1 tahun (time-to-live). Ketersediaan
sample_audio:voices.create()(CreateVoice) danvoices.get()(GetVoice) mengisisample_audio(mime_type: "audio/wav",databerenkode base64) untuk suara"prompted". Agar listingan tetap ringan,voices.list()(ListVoices) menghilangkansample_audio(dansample_audiotidak disetel untuk suara"replicated"dan"prebuilt").
Python
from google import genai
client = genai.Client()
# List stored prompted voices in your project filtered by language
response = client.voices.list(
type_=["prompted"],
language_code=["en-US", "en-GB"],
)
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=created_voice.id)
# Delete a stored custom voice
client.voices.delete(id=created_voice.id)
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI();
// List stored prompted voices in your project filtered by language
const response = await ai.voices.list({
type: ["prompted"],
language_code: ["en-US", "en-GB"],
});
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(createdVoice.id);
// Delete a stored custom voice
await ai.voices.delete(createdVoice.id);
REST
# List stored prompted voices filtered by language
curl -G "https://generativelanguage.googleapis.com/v1beta/voices" \
-H "x-goog-api-key: $GEMINI_API_KEY" \
--data-urlencode "type=prompted" \
--data-urlencode "language_code=en-US" \
--data-urlencode "language_code=en-GB"
# Retrieve a specific voice by ID
curl "https://generativelanguage.googleapis.com/v1beta/voices/voice_YOUR_DESIGNED_VOICE_ID" \
-H "x-goog-api-key: $GEMINI_API_KEY"
# Delete a stored custom voice
curl -X DELETE "https://generativelanguage.googleapis.com/v1beta/voices/voice_YOUR_DESIGNED_VOICE_ID" \
-H "x-goog-api-key: $GEMINI_API_KEY"
Praktik terbaik perintah untuk desain Voice
- Masukkan ciri vokal permanen dalam Desain suara, bukan
style: Tentukan karakteristik tetap—seperti usia, gender, timbre, karakter suara, dan aksen regional—saat membuat suara divoices.create. - Cadangkan
speech_metadata.styleuntuk emosi situasional: Setelah suara kustom Anda dibuat, gunakan perintahstylesingkat (misalnya,"whispered urgently"atau"cheerful and energetic") untuk mengarahkan akting belokan demi belokan tanpa mengubah identitas inti pembicara. - Buat perintah yang spesifik dan ringkas: Deskripsi 1–2 kalimat yang jelas (seperti "Seorang komentator olahraga yang bersemangat dan fasih di usia 30-an dengan sedikit aksen Midwest") akan menghasilkan hasil yang lebih bersih dan konsisten daripada paragraf yang bertentangan atau terlalu panjang.
Langkah berikutnya
- Pelajari cara mereplikasi suara penutur yang ada di Replikasi suara.
- Pelajari gaya tingkat giliran bicara, tag inline, dan dialog multi-penutur dalam Panduan text-to-speech.