音声設計では、Gemini API Voices エンドポイント(POST /v1beta/voices)を使用して、自然言語の説明から新しい永続的な音声ペルソナを作成できます。事前構築済みの音声や録音された参照音声に限定されるのではなく、キャラクターの年齢、音色、アクセント、ベースラインの配信を説明して、プロジェクトに保存された再利用可能な voice_... ID を受け取ることができます。
カスタム音声の設計、オーディション、反復処理を最速で行うには、Google AI Studio のインタラクティブな音声設計スタジオを使用します。テキスト プロンプトからカスタム ペルソナを生成し、サンプル スクリプトでテストして、結果の voice_... ID をアプリケーション コードに直接コピーできます。
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 エンコードされた data)が返されるため、生成された音声をすぐに試聴できます。
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
音声設計の仕組み
- プロンプト付き音声を作成する:
type="prompted"とstore=Trueを使用してvoices.create(POST /v1beta/voices)を呼び出します。 - 永続的な
voice_idとsample_audioのプレビューを受け取る: API は音声 ID を生成してプロジェクトに保存し、生成された音声のプレビュー音声を含むsample_audio(mime_type: "audio/wav"、base64 エンコードされたdata)とともに永続 ID(voice_abc123...など)を返します。 - 音声を合成する:
generateContentを呼び出すときに、speechConfig.voiceConfig.voiceでvoice_idを渡します。
設計した音声で音声を合成する
generateContent を呼び出すときに、voiceConfig.voice で返された id(voice_...)を渡します。
Python
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)
JavaScript
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"));
}
REST
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、プロンプト音声と複製音声で共有)には、プロジェクトあたり 200 音声の上限と 1 年の TTL(有効期間)があります。 sample_audioの可用性:voices.create()(CreateVoice)とvoices.get()(GetVoice)は、"prompted"音声のsample_audio(mime_type: "audio/wav"、base64 エンコードされたdata)を設定します。リストを軽量に保つため、voices.list()(ListVoices)ではsample_audioが省略されます("replicated"と"prebuilt"の音声ではsample_audioが設定されていません)。
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"
音声設計のプロンプト作成のベスト プラクティス
- 永続的な音声特性は
styleではなく Voice Design に配置する:voices.createで音声を作成するときに、年齢、性別、音色、声の質感、地域アクセントなどの不変の特性を定義します。 - 状況に応じた感情表現のために
speech_metadata.styleを予約する: カスタム音声を作成したら、短いstyleプロンプト("whispered urgently"や"cheerful and energetic"など)を使用して、話者の核となるアイデンティティを変えることなく、ターンバイターンの演技を指示します。 - 具体的かつ簡潔に: 1 ~ 2 文の明確な説明(「30 代のキレのある元気なスポーツ アナウンサーで、中西部のアクセントが少しある」など)は、矛盾した段落や長すぎる段落よりも、より明確で一貫性のある結果を生み出します。
次のステップ
- 既存のスピーカーの音声を複製する方法については、ボイス レプリケーションをご覧ください。
- テキスト読み上げガイドで、ターンレベルのスタイル設定、インライン タグ、複数話者の会話について確認してください。