طراحی صدا به شما امکان میدهد با استفاده از نقطه پایانی Gemini API Voices ( POST /v1beta/voices ) یک شخصیت صوتی کاملاً جدید و پایدار از توصیف زبان طبیعی ایجاد کنید. به جای محدود شدن به صداهای از پیش ساخته شده یا ضبط صدای مرجع، میتوانید سن، طنین صدا، لهجه و نحوهی بیان اولیهی یک شخصیت را توصیف کنید و یک شناسهی voice_... قابل استفادهی مجدد که در پروژهی شما ذخیره شده است، دریافت کنید.
سریعترین راه برای طراحی، تست صدا و تکرار صداهای سفارشی، استفاده از استودیوی تعاملی طراحی صدا در Google AI Studio است. میتوانید پرسوناهای سفارشی را از پیامهای متنی ایجاد کنید، آنها را با اسکریپتهای نمونه آزمایش کنید و شناسه voice_... حاصل را مستقیماً در کد برنامه خود کپی کنید.
هر دو نرمافزار Gemini 3.8 Flash TTS ( gemini-3.8-flash-tts ) و Gemini 3.8 Flash-Lite TTS ( gemini-3.8-flash-lite-tts ) از طراحی صوتی پشتیبانی میکنند.
یک صدای طراحیشده ایجاد کنید
از Google GenAI SDK ( google-genai 2.25.0+ / @google/genai 2.24.0+) یا REST API برای ایجاد صدای سفارشی از توضیحات متنی استفاده کنید. برای صداهای "prompted" ، هر دو voices.create ( CreateVoice ) و voices.get ( GetVoice ) یک فیلد sample_audio فقط خروجی ( mime_type: "audio/wav" , base64-encoded data ) برمیگردانند تا بتوانید بلافاصله صدای تولید شده را بشنوید:
پایتون
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))
جاوا اسکریپت
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")
);
}
استراحت
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
نحوه کار طراحی صدا
- ایجاد یک صدای درخواستی:
voices.create(POST /v1beta/voices) را باtype="prompted"وstore=Trueفراخوانی کنید. - دریافت پیشنمایش دائمی
voice_idوsample_audio: API هویت صوتی را تولید میکند، آن را در پروژه شما ذخیره میکند و یک شناسه دائمی (برای مثال،voice_abc123...) به همراهsample_audio(mime_type: "audio/wav", base64-encodeddata) که شامل صدای پیشنمایش تولید شده برای صدا است را برمیگرداند. - سنتز گفتار:
voice_idرا در هر جایی که نام صدا در درخواستهای سنتز شما پذیرفته میشود، وارد کنید.
گفتار را با صدای طراحیشده خود ترکیب کنید
پس از ایجاد صدا، id آن ( voice_... ) را برای تولید گفتار به Interactions API ارسال کنید:
پایتون
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))
جاوا اسکریپت
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"));
استراحت
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"}
]
}
}'
صداهایتان را مدیریت کنید
شما میتوانید صداهای ذخیره شده خود را در هر زمانی با استفاده از Voices API فهرست، فیلتر، بررسی و حذف کنید (برای مشاهده همه پارامترهای فیلتر ، به بخش کتابخانه صوتی توسعهیافته و فیلترینگ مراجعه کنید).
- محدودیتهای ذخیرهسازی و TTL: صداهای دارای وضعیت (
store=True، که در بین صداهای درخواستی و تکرار شده مشترک است) دارای محدودیت ۲۰۰ صدا در هر پروژه و TTL (زمان ماندگاری) ۱ ساله هستند. در دسترس بودن
sample_audio:voices.create()(CreateVoice) وvoices.get()(GetVoice) برای صداهای"prompted"sample_audio(mime_type: "audio/wav", base64-encodeddata) را پر میکنند. برای سبک نگه داشتن لیست،voices.list()(ListVoices)sample_audioحذف میکند (وsample_audioبرای صداهای"replicated"و"prebuilt"تنظیم نشده است).
پایتون
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)
جاوا اسکریپت
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);
استراحت
# 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"
ارائه بهترین شیوهها برای طراحی صدا
- ویژگیهای صوتی دائمی را در طراحی صدا قرار دهید، نه
style: هنگام ایجاد صدا درvoices.create، ویژگیهای تغییرناپذیر - مانند سن، جنسیت، طنین، بافت صوتی و لهجه منطقهای - را تعریف کنید. -
speech_metadata.styleبرای احساسات موقعیتی ذخیره کنید: پس از ایجاد صدای سفارشی خود، از عبارات کوتاهstyle(مثلاً"whispered urgently"یا"cheerful and energetic") برای هدایت نوبت به نوبت رفتار بدون تغییر هویت اصلی گوینده استفاده کنید. - دقیق و مختصر باشید: یک توصیف واضح ۱ تا ۲ جملهای (مانند «یک گوینده ورزشی سرزنده و پرانرژی، حدوداً ۳۰ ساله با لهجهی کمی غربی میانهرو» ) نتایج واضحتر و منسجمتری نسبت به پاراگرافهای متناقض یا بیش از حد طولانی ایجاد میکند.
قدم بعدی چیست؟
- یاد بگیرید که چگونه صدای گوینده موجود را در «تکرار صدا» تکرار کنید.
- سبکبندی نوبتی، تگهای درونخطی و گفتگوی چندگوینده را در راهنمای تبدیل متن به گفتار بررسی کنید.