طراحی صدا

طراحی صدا به شما امکان می‌دهد با استفاده از نقطه پایانی 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

نحوه کار طراحی صدا

  1. ایجاد یک صدای درخواستی: voices.create ( POST /v1beta/voices ) را با type="prompted" و store=True فراخوانی کنید.
  2. دریافت پیش‌نمایش دائمی voice_id و sample_audio : API هویت صوتی را تولید می‌کند، آن را در پروژه شما ذخیره می‌کند و یک شناسه دائمی (برای مثال، voice_abc123... ) به همراه sample_audio ( mime_type: "audio/wav" , base64-encoded data ) که شامل صدای پیش‌نمایش تولید شده برای صدا است را برمی‌گرداند.
  3. سنتز گفتار: هنگام فراخوانی generateContent ، voice_id در speechConfig.voiceConfig.voice وارد کنید.

گفتار را با صدای طراحی‌شده خود ترکیب کنید

id برگردانده شده ( voice_... ) را هنگام فراخوانی generateContent در voiceConfig.voice وارد کنید:

پایتون

from google import genai

client = genai.Client()

response = client.models.generate_content(
    model="gemini-3.8-flash-tts",
    contents=[{
        "role": "user",
        "parts": [{
            "text": (
                "Look out past the rings of Saturn. Those faint photons left"
                " their source millions of years ago."
            ),
            "speech_metadata": {"style": "reflective and awe-inspired"},
        }],
    }],
    config={
        "response_modalities": ["AUDIO"],
        "speech_config": {
            "voice_config": {"voice": created_voice.id}
        },
    },
)

audio_bytes = response.candidates[0].content.parts[0].inline_data.data
with open("designed_voice.wav", "wb") as f:
    f.write(audio_bytes)

جاوا اسکریپت

import * as fs from "node:fs";
import { GoogleGenAI } from "@google/genai";

const ai = new GoogleGenAI();

const response = await ai.models.generateContent({
  model: "gemini-3.8-flash-tts",
  contents: [{
    role: "user",
    parts: [{
      text: "Look out past the rings of Saturn. Those faint photons left their source millions of years ago.",
      speechMetadata: { style: "reflective and awe-inspired" },
    }],
  }],
  config: {
    responseModalities: ["AUDIO"],
    speechConfig: {
      voiceConfig: { voice: createdVoice.id },
    },
  },
});

const data = response.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;
if (data) {
  fs.writeFileSync("designed_voice.wav", Buffer.from(data, "base64"));
}

استراحت

curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-3.8-flash-tts:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -H "Content-Type: application/json" \
  -X POST \
  -d '{
    "contents": [{
      "role": "user",
      "parts": [{
        "text": "Look out past the rings of Saturn. Those faint photons left their source millions of years ago.",
        "speech_metadata": {
          "style": "reflective and awe-inspired"
        }
      }]
    }],
    "generationConfig": {
      "responseModalities": ["AUDIO"],
      "speechConfig": {
        "voiceConfig": {
          "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-encoded data ) را پر می‌کنند. برای سبک نگه داشتن لیست، 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" ) برای هدایت نوبت به نوبت رفتار بدون تغییر هویت اصلی گوینده استفاده کنید.
  • دقیق و مختصر باشید: یک توصیف واضح ۱ تا ۲ جمله‌ای (مانند «یک گوینده ورزشی سرزنده و پرانرژی، حدوداً ۳۰ ساله با لهجه‌ی کمی غربی میانه‌رو» ) نتایج واضح‌تر و منسجم‌تری نسبت به پاراگراف‌های متناقض یا بیش از حد طولانی ایجاد می‌کند.

قدم بعدی چیست؟