Text-to-Speech 中的即時自訂語音功能可讓使用者利用自己的高品質音訊錄音訓練模型,建立個人化語音模型。這項工具可快速產生個人語音,然後使用 Cloud TTS API 合成音訊,同時支援串流和長篇文字。
基於安全考量,只有在許可清單中的使用者才能使用此語音複製功能。如要使用這項功能,請與銷售團隊成員聯絡,要求對方將你加入許可清單。
![]() |
![]() |
支援的語言
即時自訂語音建立和合成功能支援以下語言:
語言 | BCP-47 代碼 | 同意聲明 |
---|---|---|
阿拉伯文 (XA) | ar-XA | .أنا مالك هذا الصوت وأوافق على أن تستخدم Google هذا الصوت لإنشاء نموذج صوتي اصطناعي |
孟加拉文 (印度) | bn-IN | আমি এই ভয়েসের মালিক এবং আমি একটি সিন্থেটিক ভয়েস মডেল তৈরি করতে এই ভয়েস ব্যবহার করে Google-এর সাথে সম্মতি দিচ্ছি। |
中文 (中國) | cmn-CN | 我是此声音的拥有者并授权谷歌使用此声音创建语音合成模型 |
德文 (德國) | de-DE | Ich bin der Eigentümer dieser Stimme und bin damit einverstanden, dass Google diese Stimme zur Erstellung eines synthetischen Stimmmodells verwendet. |
英文 (澳洲) | en-AU | 我是這個聲音的擁有者,我同意 Google 用此聲音建立合成語音模型。 |
英文 (英國) | en-GB | 我是這個聲音的擁有者,我同意 Google 用此聲音建立合成語音模型。 |
英文 (印度) | en-IN | 我是這個聲音的擁有者,我同意 Google 用此聲音建立合成語音模型。 |
英文 (美國) | en-US | 我是這個聲音的擁有者,我同意 Google 用此聲音建立合成語音模型。 |
西班牙文 (西班牙) | es-ES | Soy el propietario de esta voz y doy mi consentimiento para que Google la utilice para crear un modelo de voz sintética. |
西班牙文 (美國) | es-US | Soy el propietario de esta voz y doy mi consentimiento para que Google la utilice para crear un modelo de voz sintética. |
法文 (加拿大) | fr-CA | Je suis le propriétaire de cette voix et j'autorise Google à utiliser cette voix pour créer un modèle de voix synthétique. |
法文 (法國) | fr-FR | Je suis le propriétaire de cette voix et j'autorise Google à utiliser cette voix pour créer un modèle de voix synthétique. |
古吉拉特文 (印度) | gu-IN | હું આ વોઈસનો માલિક છું અને સિન્થેટિક વોઈસ મોડલ બનાવવા માટે આ વોઈસનો ઉપયોગ કરીને google ને હું સંમતિ આપું છું |
北印度文 (印度) | hi-IN | मैं इस आवाज का मालिक हूं और मैं सिंथेटिक आवाज मॉडल बनाने के लिए Google को इस आवाज का उपयोग करने की सहमति देता हूं |
印尼文 (印尼) | id-ID | Saya pemilik suara ini dan saya menyetujui Google menggunakan suara ini untuk membuat model suara sintetis. |
義大利文 (義大利) | it-IT | Sono il proprietario di questa voce e acconsento che Google la utilizzi per creare un modello di voce sintetica. |
日文 (日本) | ja-JP | 私はこの音声の所有者であり、Googleがこの音声を使用して音声合成モデルを作成することを承認します。 |
卡納達文 (印度) | kn-IN | ನಾನು ಈ ಧ್ವನಿಯ ಮಾಲಿಕ ಮತ್ತು ಸಂಶ್ಲೇಷಿತ ಧ್ವನಿ ಮಾದರಿಯನ್ನು ರಚಿಸಲು ಈ ಧ್ವನಿಯನ್ನು ಬಳಸಿಕೊಂಡುಗೂಗಲ್ ಗೆ ನಾನು ಸಮ್ಮತಿಸುತ್ತೇನೆ. |
韓文 (韓國) | ko-KR | 나는 이 음성의 소유자이며 구글이 이 음성을 사용하여 음성 합성 모델을 생성할 것을 허용합니다. |
馬拉雅拉姆文 (印度) | ml-IN | ഈ ശബ്ദത്തിന്റെ ഉടമ ഞാനാണ്, ഒരു സിന്തറ്റിക് വോയ്സ് മോഡൽ സൃഷ്ടിക്കാൻ ഈ ശബ്ദം ഉപയോഗിക്കുന്നതിന് ഞാൻ Google-ന് സമ്മതം നൽകുന്നു." |
馬拉地文 (印度) | mr-IN | मी या आवाजाचा मालक आहे आणि सिंथेटिक व्हॉईस मॉडेल तयार करण्यासाठी हा आवाज वापरण्यासाठी मी Google ला संमती देतो |
荷蘭文 (荷蘭) | nl-NL | Ik ben de eigenaar van deze stem en ik geef Google toestemming om deze stem te gebruiken om een synthetisch stemmodel te maken. |
波蘭文 (波蘭) | pl-PL | Jestem właścicielem tego głosu i wyrażam zgodę na wykorzystanie go przez Google w celu utworzenia syntetycznego modelu głosu. |
葡萄牙文 (巴西) | pt-BR | Eu sou o proprietário desta voz e autorizo o Google a usá-la para criar um modelo de voz sintético. |
俄文 (俄羅斯) | ru-RU | Я являюсь владельцем этого голоса и даю согласие Google на использование этого голоса для создания модели синтетического голоса. |
泰米爾文 (印度) | ta-IN | 나는 이 음성의 소유자이며, 음성으로 인공지능 음성 모델을 만들기 위해 이 음성을 사용할 수 있도록 Google 에 동의합니다. |
泰盧固文 (印度) | te-IN | నేను ఈ వాయిస్ యజమానిని మరియు సింతటిక్ వాయిస్ మోഡല് നിര്മ്മിക്കുന്നതിന്റെ ഭാഗമായി ഈ വായ്സ് ഉപയോഗിക്കുന്നതിന്റെ കാരണം ഞാന് Google നെ അറിയിക്കുകയാണ്. |
泰文 (泰國) | th-TH | ฉันเป็นเจ้าของเสียงนี้ และฉันยินยอมให้ Google ใช้เสียงนี้เพื่อสร้างแบบจำลองเสียงสังเคราะห์ |
土耳其文 (土耳其) | tr-TR | Bu sesin sahibi benim ve Google'ın bu sesi kullanarak sentetik bir ses modeli oluşturmasına izin veriyorum. |
越南文 (越南) | vi-VN | Tôi là chủ sở hữu giọng nói này và tôi đồng ý cho Google sử dụng giọng nói này để tạo mô hình giọng nói tổng hợp. |
地區可用性
即時自訂語音建立和合成功能分別適用於下列 Google Cloud 區域:
Google Cloud 可用區 | 支援的方法 | 發布準備完成度 |
---|---|---|
global |
創作、合成 | 不公開預先發布版 |
us |
整合 | 不公開預先發布版 |
eu |
整合 | 不公開預先發布版 |
asia-southeast1 |
整合 | 不公開預先發布版 |
支援的輸出格式
預設回應格式為 LINEAR16,但支援的其他格式包括:
API 方法 | 格式 |
---|---|
streaming |
ALAW、MULAW、OGG_OPUS 和 PCM |
batch |
ALAW、MULAW、MP3、OGG_OPUS 和 PCM |
功能支援與限制
功能 | 支援 | 說明 |
---|---|---|
SSML | 否 | 使用 SSML 標記為合成音訊客製化 |
文字提示 | 實驗功能 | 使用標點符號、停頓和口吃,為文字轉語音功能增添自然的流暢度和節奏。 |
時間戳記 | 否 | 字詞層級時間戳記 |
暫停代碼 | 否 | 在合成音訊中加入暫停功能 |
配速控制 | 否 | 調整合成音訊的速度,從 0.25 倍速度到 2 倍速度。 |
發音控制 | 否 | 使用 IPA 或 X-SAMPA 語音編碼,為字詞或詞組設定自訂發音 |
使用 Chirp 3:即時自訂語音
以下各節將探討如何在 Text-to-Speech API 中使用 Chirp 3:即時自訂語音功能。
錄製同意聲明和參考音訊
- 錄製同意聲明:為遵守 Instant Custom Voice 的法律和道德規範,請以適當語言,使用 LINEAR16 編碼和 24 kHz 取樣率,錄製必要的同意聲明,並儲存為單聲道 WAV 檔案。(「我是這個聲音的擁有者,我同意 Google 用此聲音建立合成語音模型」)。
- 錄製參考音訊:使用電腦麥克風錄製最多 10 秒的音訊,並以 24 kHz 取樣率的 LINEAR16 編碼單聲道 WAV 檔案格式儲存。錄製時請避免有背景噪音。同意聲明和參考音訊必須在相同環境下錄製。
- 儲存音訊檔案:將錄製的音訊檔案儲存在指定的 Cloud Storage 位置。
使用 REST API 建立即時自訂語音
import requests, os, json
def create_instant_custom_voice_key(
access_token, project_id, reference_audio_bytes, consent_audio_bytes
):
url = "https://texttospeech.googleapis.com/v1beta1/voices:generateVoiceCloningKey"
request_body = {
"reference_audio": {
"audio_config": {"audio_encoding": "LINEAR16", "sample_rate_hertz": 24000},
"content": reference_audio_bytes,
},
"voice_talent_consent": {
"audio_config": {"audio_encoding": "LINEAR16", "sample_rate_hertz": 24000},
"content": consent_audio_bytes,
},
"consent_script": "I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model.",
"language_code": "en-US",
}
try:
headers = {
"Authorization": f"Bearer {access_token}",
"x-goog-user-project": project_id,
"Content-Type": "application/json; charset=utf-8",
}
response = requests.post(url, headers=headers, json=request_body)
response.raise_for_status()
response_json = response.json()
return response_json.get("voiceCloningKey")
except requests.exceptions.RequestException as e:
print(f"Error making API request: {e}")
except json.JSONDecodeError as e:
print(f"Error decoding JSON response: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
使用 REST API 以即時自訂語音合成
import requests, os, json, base64
from IPython.display import Audio, display
def synthesize_text_with_cloned_voice(access_token, project_id, voice_key, text):
url = "https://texttospeech.googleapis.com/v1beta1/text:synthesize"
request_body = {
"input": {
"text": text
},
"voice": {
"language_code": "en-US",
"voice_clone": {
"voice_cloning_key": voice_key,
}
},
"audioConfig": {
"audioEncoding": "LINEAR16",
"sample_rate_hertz": 24000
}
}
try:
headers = {
"Authorization": f"Bearer {access_token}",
"x-goog-user-project": project_id,
"Content-Type": "application/json; charset=utf-8"
}
response = requests.post(url, headers=headers, json=request_body)
response.raise_for_status()
response_json = response.json()
audio_content = response_json.get("audioContent")
if audio_content:
display(Audio(base64.b64decode(audio_content), rate=24000))
else:
print("Error: Audio content not found in the response.")
print(response_json)
except requests.exceptions.RequestException as e:
print(f"Error making API request: {e}")
except json.JSONDecodeError as e:
print(f"Error decoding JSON response: {e}")
except Exception as e:
print(f"An unexpected error occurred: {e}")
使用 Python 用戶端程式庫,以即時自訂語音合成語音
本範例使用 Python 用戶端程式庫,透過儲存在 voice_cloning_key.txt
的語音複製金鑰執行即時自訂語音合成。如要產生語音複製金鑰,請參閱「使用 REST API 建立即時自訂語音」。
from google.cloud import texttospeech
from google.cloud.texttospeech_v1beta1.services.text_to_speech import client
def perform_voice_cloning(
voice_cloning_key: str,
transcript: str,
language_code: str,
synthesis_output_path: str,
tts_client: client.TextToSpeechClient,
) -> None:
"""Perform voice cloning and write output to a file.
Args:
voice_cloning_key: The voice cloning key.
transcript: The transcript to synthesize.
language_code: The language code.
synthesis_output_path: The synthesis audio output path.
tts_client: The TTS client to use.
"""
voice_clone_params = texttospeech.VoiceCloneParams(
voice_cloning_key=voice_cloning_key
)
voice = texttospeech.VoiceSelectionParams(
language_code=language_code, voice_clone=voice_clone_params
)
request = texttospeech.SynthesizeSpeechRequest(
input=texttospeech.SynthesisInput(text=transcript),
voice=voice,
audio_config=texttospeech.AudioConfig(
audio_encoding=texttospeech.AudioEncoding.LINEAR16,
sample_rate_hertz=24000,
),
)
response = tts_client.synthesize_speech(request)
with open(synthesis_output_path, 'wb') as out:
out.write(response.audio_content)
print(f'Audio content written to file {synthesis_output_path}.')
if __name__ == '__main__':
client = texttospeech.TextToSpeechClient()
with open('voice_cloning_key.txt', 'r') as f:
key = f.read()
perform_voice_cloning(
voice_cloning_key=key,
transcript='Hello world!',
language_code='en-US',
synthesis_output_path='/tmp/output.wav',
tts_client=client,
)
使用 Python 用戶端程式庫,以即時自訂語音進行串流合成
本範例使用 Python 用戶端程式庫,使用儲存在 voice_cloning_key.txt
的語音複製金鑰,執行即時自訂語音串流合成作業。如要產生語音複製金鑰,請參閱「使用 REST API 建立即時自訂語音」。
import io
import wave
from google.cloud import texttospeech
from google.cloud.texttospeech_v1beta1.services.text_to_speech import client
def perform_voice_cloning_with_simulated_streaming(
voice_cloning_key: str,
simulated_streamed_text: list[str],
language_code: str,
synthesis_output_path: str,
tts_client: client.TextToSpeechClient,
) -> None:
"""Perform voice cloning for a given reference audio, voice talent consent, and consent script.
Args:
voice_cloning_key: The voice cloning key.
simulated_streamed_text: The list of transcripts to synthesize, where each
item represents a chunk of streamed text. This is used to simulate
streamed text input and is not meant to be representative of real-world
streaming usage.
language_code: The language code.
synthesis_output_path: The path to write the synthesis audio output to.
tts_client: The TTS client to use.
"""
voice_clone_params = texttospeech.VoiceCloneParams(
voice_cloning_key=voice_cloning_key
)
streaming_config = texttospeech.StreamingSynthesizeConfig(
voice=texttospeech.VoiceSelectionParams(
language_code=language_code, voice_clone=voice_clone_params
),
streaming_audio_config=texttospeech.StreamingAudioConfig(
audio_encoding=texttospeech.AudioEncoding.PCM,
sample_rate_hertz=24000,
),
)
config_request = texttospeech.StreamingSynthesizeRequest(
streaming_config=streaming_config
)
# Request generator. Consider using Gemini or another LLM with output
# streaming as a generator.
def request_generator():
yield config_request
for text in simulated_streamed_text:
yield texttospeech.StreamingSynthesizeRequest(
input=texttospeech.StreamingSynthesisInput(text=text)
)
streaming_responses = tts_client.streaming_synthesize(request_generator())
audio_buffer = io.BytesIO()
for response in streaming_responses:
print(f'Audio content size in bytes is: {len(response.audio_content)}')
audio_buffer.write(response.audio_content)
# Write collected audio outputs to a WAV file.
with wave.open(synthesis_output_path, 'wb') as wav_file:
wav_file.setnchannels(1)
wav_file.setsampwidth(2)
wav_file.setframerate(24000)
wav_file.writeframes(audio_buffer.getvalue())
print(f'Audio content written to file {synthesis_output_path}.')
if __name__ == '__main__':
client = texttospeech.TextToSpeechClient()
with open('voice_cloning_key.txt', 'r') as f:
key = f.read()
perform_voice_cloning_with_simulated_streaming(
voice_cloning_key=key,
simulated_streamed_text=[
'Hello world!',
'This is the second text chunk.',
'This simulates streaming text for synthesis.',
],
language_code='en-US',
synthesis_output_path='streaming_output.wav',
tts_client=client,
)