Gemini-TTS

Text-to-Speech Gemini-TTS 是我們最新的文字轉語音技術,不僅能生成自然流暢的語音,還可透過文字提示精細控制生成的音訊。透過 Gemini-TTS,您可以從短片段到長篇敘事,合成語音,精確地決定風格、口音、速度、語調,甚至是情緒表達,所有這些都可以透過自然語言提示來引導。

下列項目支援 Gemini-TTS 功能:

  • gemini-2.5-flash-preview-tts:Gemini 2.5 Flash 預先發布版適合用於日常應用程式,可節省成本。

  • gemini-2.5-pro-preview-tts:Gemini 2.5 Pro 預先發布版適合用於可控的語音生成 (TTS),以及複雜提示的頂尖品質。

模型 適合用途 輸入模態 輸出模態 單一說話者
Gemini 2.5 Flash 預先發布版 TTS 延遲時間短、可控制、單一和多位說話者文字轉語音音訊生成,適用於日常應用程式,經濟實惠 文字 音訊 ✔️
Gemini 2.5 Pro 預先發布版 TTS 高度控管結構化工作流程,例如生成 Podcast、有聲書、客戶服務等 文字 音訊 ✔️

其他控制項和功能包括:

  1. 自然對話:語音互動品質極佳,表達方式和韻律 (節奏模式) 更貼近自然,且延遲時間極短,讓對話流暢無礙。

  2. 風格控制:使用自然語言提示,即可在對話中調整語氣,引導語音採用特定口音,並產生各種語調和表情,包括耳語。

  3. 動態表現:這些模型可生動朗讀文字,例如詩歌、新聞報導和引人入勝的故事。還能依要求以特定情緒表演,並產生口音。

  4. 加強語速和發音控制:控制語速有助於確保發音更準確,包括特定字詞。

範例

model: "gemini-2.5-pro-preview-tts"
prompt: "You are having a casual conversation with a friend. Say the following in a friendly and amused way."
text: "hahah I did NOT expect that. Can you believe it!."
speaker: "Callirhoe"

model: "gemini-2.5-flash-preview-tts"
prompt: "Say the following in a curious way"
text: "OK, so... tell me about this [uhm] AI thing.",
speaker: "Orus"

model: "gemini-2.5-flash-preview-tts"
prompt: "Say the following"
text: "[extremely fast] Availability and terms may vary. Check our website or your local store for complete details and restrictions."
speaker: "Kore"

如要瞭解如何以程式輔助方式使用這些聲音,請參閱「使用 Gemini-TTS」一節。

語音選項

Gemini-TTS 提供多種語音選項,與現有的 Chirp 3:HD 語音類似,但各有不同特徵:

名稱 性別 示範
Achernar 女性
Achird 男性
Algenib 男性
Algieba 男性
Alnilam 男性
Aoede 女性
Autonoe 女性
Callirrhoe 女性
冥衛一 男性
Despina 女性
安塞拉杜斯 男性
Erinome 女性
芬里爾 男性
Gacrux 女性
埃爾皮塔斯 男性
Kore 女性
Laomedeia 女性
Leda 女性
Orus 男性
Pulcherrima 女性
球餅 男性
Rasalgethi 男性
Sadachbia 男性
Sadaltager 男性
Schedar 男性
Sulafat 女性
Umbriel 男性
Vindemiatrix 女性
Zephyr 女性
Zubenelgenubi 男性

支援的語言

Gemini-TTS 提供多種語音選項,與現有的 Chirp 3:HD 語音類似,但各有不同特徵:

語言 BCP-47 代碼
英文 (美國) en-US

區域可用性

Gemini-TTS 模型適用於下列 Google Cloud 區域:

Google Cloud 區域 發布準備完成度
us 公開預先發布版

支援的輸出格式

預設回應格式為 LINEAR16。其他支援的格式包括:

API 方法 格式
batch ALAW、MULAW、MP3、OGG_OPUS 和 PCM

使用 Gemini-TTS

瞭解如何使用 Gemini-TTS 模型合成單一說話者的語音。

執行同步語音合成要求

Python

# google-cloud-texttospeech minimum version 2.29.0 is required.

import os
from google.cloud import texttospeech

PROJECT_ID = os.getenv("GOOGLE_CLOUD_PROJECT")

def synthesize(prompt: str, text: str, model_name: str, output_filepath: str = "output.mp3"):
   """Synthesizes speech from the input text and saves it to an MP3 file.

   Args:
       prompt: Stylisting instructions on how to synthesize the content in
         the text field.
       text: The text to synthesize.
       model_name: Gemini model to use. Currently, the available models are
         gemini-2.5-flash-preview-tts and gemini-2.5-pro-preview-tts
       output_filepath: The path to save the generated audio file.
         Defaults to "output.mp3".
   """
   client = texttospeech.TextToSpeechClient()

   synthesis_input = texttospeech.SynthesisInput(text=text, prompt=prompt)

   # Select the voice you want to use.
   voice = texttospeech.VoiceSelectionParams(
       language_code="en-US",
       name="Charon",  # Example voice, adjust as needed
       model_name=model_name
   )

   audio_config = texttospeech.AudioConfig(
       audio_encoding=texttospeech.AudioEncoding.MP3
   )

   # Perform the text-to-speech request on the text input with the selected
   # voice parameters and audio file type.
   response = client.synthesize_speech(
       input=synthesis_input, voice=voice, audio_config=audio_config
   )

   # The response's audio_content is binary.
   with open(output_filepath, "wb") as out:
       out.write(response.audio_content)
       print(f"Audio content written to file: {output_filepath}")

CURL

# Make sure to install gcloud cli, and sign in to your project.
# Make sure to use your PROJECT_ID value.
# Currently, the available models are gemini-2.5-flash-preview-tts and gemini-2.5-pro-preview-tts
# To parse the JSON output and use it directly see the last line of the command.
# Requires JQ and ffplay library to be installed.
PROJECT_ID=YOUR_PROJECT_ID
curl -X POST \
-H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
-H "x-goog-user-project: $PROJECT_ID" \
-H "Content-Type: application/json" \
-d '{
"input": {
  "prompt": "Say the following in a curious way",
  "text": "OK, so... tell me about this [uhm] AI thing."
},
"voice": {
  "languageCode": "en-us",
  "name": "Kore",
  "model_name": "gemini-2.5-flash-preview-tts"
},
"audioConfig": {
  "audioEncoding": "LINEAR16"
}
}' \
"https://texttospeech.googleapis.com/v1/text:synthesize" \
| jq -r '.audioContent' | base64 -d | ffplay - -autoexit