Gemini API は、ネイティブのテキスト読み上げ(TTS)生成機能を使用して、テキスト入力を単一話者または複数話者の音声に変換できます。テキスト読み上げ(TTS)の生成は制御可能です。つまり、自然言語を使用してインタラクションを構造化し、音声のスタイル、アクセント、ペース、トーンをガイドできます。
TTS 機能は、インタラクティブな非構造化音声、マルチモーダル入力と出力用に設計された Live API を介して提供される音声生成とは異なります。Live API は動的な会話コンテキストに優れていますが、Gemini API を介した TTS は、ポッドキャストやオーディオブックの生成など、スタイルやサウンドをきめ細かく制御して正確なテキスト朗読が必要なシナリオ向けに調整されています。
このガイドでは、テキストから単一話者と複数話者の音声を生成する方法について説明します。
始める前に
サポートされているモデル セクションに記載されているように、ネイティブのテキスト読み上げ(TTS)機能を備えた Gemini 2.5 モデル バリアントを使用してください。最適な結果を得るには、特定のユースケースに最適なモデルを検討してください。
構築を開始する前に、AI Studio で Gemini 2.5 TTS モデルをテストすることをおすすめします。
1 人の話し手のテキスト読み上げ
テキストを単一話者の音声に変換するには、レスポンス モダリティを「音声」に設定し、VoiceConfig を設定した SpeechConfig オブジェクトを渡します。事前構築済みの出力音声から音声名を選択する必要があります。
この例では、モデルからの出力音声を wave ファイルに保存します。
Python
from google import genai
from google.genai import types
import wave
# Set up the wave file to save the output:
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
   with wave.open(filename, "wb") as wf:
      wf.setnchannels(channels)
      wf.setsampwidth(sample_width)
      wf.setframerate(rate)
      wf.writeframes(pcm)
client = genai.Client()
response = client.models.generate_content(
   model="gemini-2.5-flash-preview-tts",
   contents="Say cheerfully: Have a wonderful day!",
   config=types.GenerateContentConfig(
      response_modalities=["AUDIO"],
      speech_config=types.SpeechConfig(
         voice_config=types.VoiceConfig(
            prebuilt_voice_config=types.PrebuiltVoiceConfig(
               voice_name='Kore',
            )
         )
      ),
   )
)
data = response.candidates[0].content.parts[0].inline_data.data
file_name='out.wav'
wave_file(file_name, data) # Saves the file to current directory
JavaScript
import {GoogleGenAI} from '@google/genai';
import wav from 'wav';
async function saveWaveFile(
   filename,
   pcmData,
   channels = 1,
   rate = 24000,
   sampleWidth = 2,
) {
   return new Promise((resolve, reject) => {
      const writer = new wav.FileWriter(filename, {
            channels,
            sampleRate: rate,
            bitDepth: sampleWidth * 8,
      });
      writer.on('finish', resolve);
      writer.on('error', reject);
      writer.write(pcmData);
      writer.end();
   });
}
async function main() {
   const ai = new GoogleGenAI({});
   const response = await ai.models.generateContent({
      model: "gemini-2.5-flash-preview-tts",
      contents: [{ parts: [{ text: 'Say cheerfully: Have a wonderful day!' }] }],
      config: {
            responseModalities: ['AUDIO'],
            speechConfig: {
               voiceConfig: {
                  prebuiltVoiceConfig: { voiceName: 'Kore' },
               },
            },
      },
   });
   const data = response.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;
   const audioBuffer = Buffer.from(data, 'base64');
   const fileName = 'out.wav';
   await saveWaveFile(fileName, audioBuffer);
}
await main();
REST
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-tts:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
        "contents": [{
          "parts":[{
            "text": "Say cheerfully: Have a wonderful day!"
          }]
        }],
        "generationConfig": {
          "responseModalities": ["AUDIO"],
          "speechConfig": {
            "voiceConfig": {
              "prebuiltVoiceConfig": {
                "voiceName": "Kore"
              }
            }
          }
        },
        "model": "gemini-2.5-flash-preview-tts",
    }' | jq -r '.candidates[0].content.parts[0].inlineData.data' | \
          base64 --decode >out.pcm
# You may need to install ffmpeg.
ffmpeg -f s16le -ar 24000 -ac 1 -i out.pcm out.wav
複数話者のテキスト読み上げ
マルチスピーカー オーディオの場合、各スピーカー(最大 2 つ)が SpeakerVoiceConfig として構成された MultiSpeakerVoiceConfig オブジェクトが必要です。各 speaker は、プロンプトで使用されている名前と同じ名前で定義する必要があります。
Python
from google import genai
from google.genai import types
import wave
# Set up the wave file to save the output:
def wave_file(filename, pcm, channels=1, rate=24000, sample_width=2):
   with wave.open(filename, "wb") as wf:
      wf.setnchannels(channels)
      wf.setsampwidth(sample_width)
      wf.setframerate(rate)
      wf.writeframes(pcm)
client = genai.Client()
prompt = """TTS the following conversation between Joe and Jane:
         Joe: How's it going today Jane?
         Jane: Not too bad, how about you?"""
response = client.models.generate_content(
   model="gemini-2.5-flash-preview-tts",
   contents=prompt,
   config=types.GenerateContentConfig(
      response_modalities=["AUDIO"],
      speech_config=types.SpeechConfig(
         multi_speaker_voice_config=types.MultiSpeakerVoiceConfig(
            speaker_voice_configs=[
               types.SpeakerVoiceConfig(
                  speaker='Joe',
                  voice_config=types.VoiceConfig(
                     prebuilt_voice_config=types.PrebuiltVoiceConfig(
                        voice_name='Kore',
                     )
                  )
               ),
               types.SpeakerVoiceConfig(
                  speaker='Jane',
                  voice_config=types.VoiceConfig(
                     prebuilt_voice_config=types.PrebuiltVoiceConfig(
                        voice_name='Puck',
                     )
                  )
               ),
            ]
         )
      )
   )
)
data = response.candidates[0].content.parts[0].inline_data.data
file_name='out.wav'
wave_file(file_name, data) # Saves the file to current directory
JavaScript
import {GoogleGenAI} from '@google/genai';
import wav from 'wav';
async function saveWaveFile(
   filename,
   pcmData,
   channels = 1,
   rate = 24000,
   sampleWidth = 2,
) {
   return new Promise((resolve, reject) => {
      const writer = new wav.FileWriter(filename, {
            channels,
            sampleRate: rate,
            bitDepth: sampleWidth * 8,
      });
      writer.on('finish', resolve);
      writer.on('error', reject);
      writer.write(pcmData);
      writer.end();
   });
}
async function main() {
   const ai = new GoogleGenAI({});
   const prompt = `TTS the following conversation between Joe and Jane:
         Joe: How's it going today Jane?
         Jane: Not too bad, how about you?`;
   const response = await ai.models.generateContent({
      model: "gemini-2.5-flash-preview-tts",
      contents: [{ parts: [{ text: prompt }] }],
      config: {
            responseModalities: ['AUDIO'],
            speechConfig: {
               multiSpeakerVoiceConfig: {
                  speakerVoiceConfigs: [
                        {
                           speaker: 'Joe',
                           voiceConfig: {
                              prebuiltVoiceConfig: { voiceName: 'Kore' }
                           }
                        },
                        {
                           speaker: 'Jane',
                           voiceConfig: {
                              prebuiltVoiceConfig: { voiceName: 'Puck' }
                           }
                        }
                  ]
               }
            }
      }
   });
   const data = response.candidates?.[0]?.content?.parts?.[0]?.inlineData?.data;
   const audioBuffer = Buffer.from(data, 'base64');
   const fileName = 'out.wav';
   await saveWaveFile(fileName, audioBuffer);
}
await main();
REST
curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash-preview-tts:generateContent" \
  -H "x-goog-api-key: $GEMINI_API_KEY" \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
  "contents": [{
    "parts":[{
      "text": "TTS the following conversation between Joe and Jane:
                Joe: Hows it going today Jane?
                Jane: Not too bad, how about you?"
    }]
  }],
  "generationConfig": {
    "responseModalities": ["AUDIO"],
    "speechConfig": {
      "multiSpeakerVoiceConfig": {
        "speakerVoiceConfigs": [{
            "speaker": "Joe",
            "voiceConfig": {
              "prebuiltVoiceConfig": {
                "voiceName": "Kore"
              }
            }
          }, {
            "speaker": "Jane",
            "voiceConfig": {
              "prebuiltVoiceConfig": {
                "voiceName": "Puck"
              }
            }
          }]
      }
    }
  },
  "model": "gemini-2.5-flash-preview-tts",
}' | jq -r '.candidates[0].content.parts[0].inlineData.data' | \
    base64 --decode > out.pcm
# You may need to install ffmpeg.
ffmpeg -f s16le -ar 24000 -ac 1 -i out.pcm out.wav
プロンプトで音声スタイルを制御する
単一話者と複数話者の両方の TTS で、自然言語プロンプトを使用してスタイル、トーン、アクセント、ペースを制御できます。たとえば、1 人のスピーカーのプロンプトでは、次のように話しかけます。
Say in an spooky whisper:
"By the pricking of my thumbs...
Something wicked this way comes"
複数話者のプロンプトでは、各話者の名前と対応する文字起こしをモデルに提供します。スピーカーごとに個別にガイダンスを提供することもできます。
Make Speaker1 sound tired and bored, and Speaker2 sound excited and happy:
Speaker1: So... what's on the agenda today?
Speaker2: You're never going to guess!
伝えたいスタイルや感情に対応する音声オプションを使用すると、さらに強調できます。たとえば、前のプロンプトでは、エンケラドゥスの息遣いが「疲れた」や「退屈」を強調し、パックの明るいトーンが「興奮」や「幸せ」を補完する可能性があります。
音声に変換するプロンプトを生成しています
TTS モデルは音声のみを出力しますが、他のモデルを使用して最初に文字起こしを生成し、その文字起こしを TTS モデルに渡して読み上げることができます。
Python
from google import genai
from google.genai import types
client = genai.Client()
transcript = client.models.generate_content(
   model="gemini-2.0-flash",
   contents="""Generate a short transcript around 100 words that reads
            like it was clipped from a podcast by excited herpetologists.
            The hosts names are Dr. Anya and Liam.""").text
response = client.models.generate_content(
   model="gemini-2.5-flash-preview-tts",
   contents=transcript,
   config=types.GenerateContentConfig(
      response_modalities=["AUDIO"],
      speech_config=types.SpeechConfig(
         multi_speaker_voice_config=types.MultiSpeakerVoiceConfig(
            speaker_voice_configs=[
               types.SpeakerVoiceConfig(
                  speaker='Dr. Anya',
                  voice_config=types.VoiceConfig(
                     prebuilt_voice_config=types.PrebuiltVoiceConfig(
                        voice_name='Kore',
                     )
                  )
               ),
               types.SpeakerVoiceConfig(
                  speaker='Liam',
                  voice_config=types.VoiceConfig(
                     prebuilt_voice_config=types.PrebuiltVoiceConfig(
                        voice_name='Puck',
                     )
                  )
               ),
            ]
         )
      )
   )
)
# ...Code to stream or save the output
JavaScript
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
async function main() {
const transcript = await ai.models.generateContent({
   model: "gemini-2.0-flash",
   contents: "Generate a short transcript around 100 words that reads like it was clipped from a podcast by excited herpetologists. The hosts names are Dr. Anya and Liam.",
   })
const response = await ai.models.generateContent({
   model: "gemini-2.5-flash-preview-tts",
   contents: transcript,
   config: {
      responseModalities: ['AUDIO'],
      speechConfig: {
         multiSpeakerVoiceConfig: {
            speakerVoiceConfigs: [
                   {
                     speaker: "Dr. Anya",
                     voiceConfig: {
                        prebuiltVoiceConfig: {voiceName: "Kore"},
                     }
                  },
                  {
                     speaker: "Liam",
                     voiceConfig: {
                        prebuiltVoiceConfig: {voiceName: "Puck"},
                    }
                  }
                ]
              }
            }
      }
  });
}
// ..JavaScript code for exporting .wav file for output audio
await main();
音声オプション
TTS モデルは、voice_name フィールドで次の 30 個の音声オプションをサポートしています。
| Zephyr - Bright | Puck -- Upbeat | Charon - 情報が豊富 | 
| Kore -- Firm | Fenrir -- Excitable | Leda -- Youthful | 
| Orus -- Firm | Aoede -- Breezy | Callirrhoe - おおらか | 
| Autonoe -- Bright | Enceladus - Breathy | Iapetus -- クリア | 
| Umbriel -- Easy-going | Algieba -- Smooth | Despina -- Smooth | 
| Erinome -- クリア | Algenib -- Gravelly | Rasalgethi - 情報が豊富 | 
| Laomedeia - アップビート | Achernar -- Soft | Alnilam -- Firm | 
| Schedar -- Even | Gacrux -- 成人向け | Pulcherrima - Forward | 
| Achird -- フレンドリー | Zubenelgenubi -- Casual | Vindemiatrix - Gentle | 
| Sadachbia -- Lively | Sadaltager -- 知識が豊富 | Sulafat -- Warm | 
AI Studio で、すべての音声オプションを聞くことができます。
サポートされている言語
TTS モデルは入力言語を自動的に検出します。次の 24 言語をサポートしています。
| 言語 | BCP-47 コード | 言語 | BCP-47 コード | 
|---|---|---|---|
| アラビア語(エジプト) | ar-EG | ドイツ語(ドイツ) | de-DE | 
| 英語(米国) | en-US | スペイン語(米国) | es-US | 
| フランス語(フランス) | fr-FR | ヒンディー語(インド) | hi-IN | 
| インドネシア語(インドネシア) | id-ID | イタリア語(イタリア) | it-IT | 
| 日本語(日本) | ja-JP | 韓国語(韓国) | ko-KR | 
| ポルトガル語(ブラジル) | pt-BR | ロシア語(ロシア) | ru-RU | 
| オランダ語(オランダ) | nl-NL | ポーランド語(ポーランド) | pl-PL | 
| タイ語(タイ) | th-TH | トルコ語(トルコ) | tr-TR | 
| ベトナム語(ベトナム) | vi-VN | ルーマニア語(ルーマニア) | ro-RO | 
| ウクライナ語(ウクライナ) | uk-UA | ベンガル語(バングラデシュ) | bn-BD | 
| 英語(インド) | en-INとhi-INのセット | マラーティー語(インド) | mr-IN | 
| タミル語(インド) | ta-IN | テルグ語(インド) | te-IN | 
サポートされているモデル
| モデル | 単一話者 | マルチスピーカー | 
|---|---|---|
| Gemini 2.5 Flash プレビュー TTS | ✔️ | ✔️ | 
| Gemini 2.5 Pro プレビュー TTS | ✔️ | ✔️ | 
制限事項
- TTS モデルはテキスト入力のみを受け取り、音声出力を生成できます。
- TTS セッションのコンテキスト ウィンドウの上限は 32,000 トークンです。
- 言語のサポートについては、言語セクションをご覧ください。
次のステップ
- 音声生成クックブックを試す。
- Gemini の Live API は、他のモダリティと組み合わせることができるインタラクティブな音声生成オプションを提供します。
- 音声入力の操作については、音声認識ガイドをご覧ください。