借助 Chirp 3 的即时自定义语音功能,您可以使用自己的高品质音频录音来训练模型,从而创建个性化语音模型。即时自定义语音可以快速生成个人语音,然后可以使用 Cloud Text-to-Speech API 将这些个人语音合成音频,该 API 同时支持流式传输和长文本。
技术详情
| 支持的语言 | 请参阅支持的语言 |
|---|---|
| 区域可用性 | global、us、eu、asia-southeast1、asia-northeast1、europe-west2 |
| 支持的输出格式 |
|
| 支持的编码格式 | LINEAR16、PCM、MP3、M4A |
| 支持的功能 |
|
支持的语言
即时自定义语音支持以下语言:
| 语言 | BCP-47 代码 | 意见声明 |
|---|---|---|
| 阿拉伯语 (XA) | ar-XA | .أنا مالك هذا الصوت وأوافق على أن تستخدم Google هذا الصوت لإنشاء نموذج صوتي اصطناعي |
| 孟加拉语(印度) | bn-IN | আমি এই ভয়েসের মালিক এবং আমি একটি সিন্থেটিক ভয়েস মডেল তৈরি করতে এই ভয়েস ব্যবহার করে Google-এর সাথে সম্মতি দিচ্ছি। |
| 中文(中国) | cmn-CN | 我是此声音的拥有者并授权谷歌使用此声音创建语音合成模型 |
| 英语(澳大利亚) | en-AU | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 英语(印度) | en-IN | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 英语(英国) | en-GB | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 英语(美国) | en-US | I am the owner of this voice and I consent to Google using this voice to create a synthetic voice model. |
| 法语(加拿大) | 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. |
| 德语(德国) | de-DE | Ich bin der Eigentümer dieser Stimme und bin damit einverstanden, dass Google diese Stimme zur Erstellung eines synthetischen Stimmmodells verwendet. |
| 古吉拉特语(印度) | 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ética. |
| 俄语(俄罗斯) | ru-RU | Я являюсь владельцем этого голоса и даю согласие Google на использование этого голоса для создания модели синтетического голоса. |
| 泰米尔语(印度) | ta-IN | நான் இந்த குரலின் உரிமையாளர் மற்றும் செயற்கை குரல் மாதிரியை உருவாக்க இந்த குரலை பயன்படுத்த குகல்க்கு நான் ஒப்புக்கொள்கிறேன். |
| 泰卢固语(印度) | 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. |
| 西班牙语(西班牙) | 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. |
使用即时自定义语音
以下部分将探讨如何在 Text-to-Speech API 中使用 Chirp 3:即时自定义语音功能。
录制同意书和参考音频
录制同意声明:为了遵守有关即时自定义语音的法律和道德准则,请使用适当的语言录制所需的同意声明,并将其保存为单声道音频文件,采用支持的音频编码,时长不超过 10 秒。(“本人是此语音的所有者,并同意 Google 使用此语音来创建合成语音模型。”)
录制参考音频:使用计算机麦克风录制最多 10 秒的音频,并以支持的音频编码保存为单声道音频文件。录制过程中不应有背景噪音。在同一环境中录制同意音频和参考音频。
存储音频文件:将录制的音频文件保存在指定的 Cloud Storage 位置。
有关制作高质量参考音频和同意书音频的指南
请遵循以下准则来制作高质量的参考音频和同意音频:
- 音频时长应尽可能接近 10 秒。
- 音频应包含自然的停顿和节奏。
- 音频应尽可能减少背景噪声。
- 如需了解详情,请参阅支持的音频编码。可以使用任何采样率。
- 该模型会复制麦克风的质量,因此如果录音听起来模糊不清,输出也会听起来模糊不清。
- 声音应富有活力,比最终输出的声音更具表现力。该语音还应具有您希望克隆的语音所具有的语调。例如,如果参考音频中没有自然的停顿或中断,则克隆的声音将无法很好地停顿。
- 好的提示比单调乏味的提示更令人兴奋和充满活力,这样模型就会根据提示来复制这种活力。
使用 REST API 创建即时自定义语音
即时自定义语音以语音克隆密钥的形式呈现,这是语音数据的文本字符串表示形式。
重要注意事项
以下是关于创建自定义语音的一些要点:
- 您可以创建的语音克隆密钥数量没有限制,因为语音克隆密钥存储在客户端,并按请求提供。
- 多个客户端或设备可以同时使用同一个声音克隆密钥。
- 每个项目每分钟最多可以创建 10 个语音克隆密钥。如需了解详情,请参阅请求限制。
- 您无法使用自定义同意声明脚本来代替默认脚本。您必须使用所选语言的同意声明脚本。
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": { # Supported audio_encoding values are LINEAR16, PCM, MP3, and M4A. "audio_config": {"audio_encoding": "LINEAR16"}, "content": reference_audio_bytes, }, "voice_talent_consent": { # Supported audio_encoding values are LINEAR16, PCM, MP3, and M4A. "audio_config": {"audio_encoding": "LINEAR16"}, "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 通过即时自定义语音进行合成
使用语音克隆密钥通过 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": { # Supported audio_encoding values are LINEAR16, PCM, MP3, and M4A. "audioEncoding": "LINEAR16", } } 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, ) 使用 Chirp 3:高清语音控制
即时自定义语音支持与 Chirp 3:高清语音相同的节奏控制、暂停控制和自定义发音功能。如需详细了解 Chirp 3:高清语音控制,请参阅 Chirp 3:高清语音控制。
您可以像启用即时自定义语音一样,通过调整 SynthesizeSpeechRequest 或 StreamingSynthesizeConfig 来为即时自定义语音启用这三项功能。
语音控制支持的语言
语速控制适用于所有语言区域。
暂停控制适用于所有语言区域。
自定义发音功能适用于除以下语言区域之外的所有语言区域:
bn-IN、gu-IN、th-TH和vi-VN。
启用多语言转移
即时自定义语音支持指定语言对之间的多语言转移。这意味着,如果使用给定的语言代码(例如 en-US)生成语音克隆密钥,则该密钥可用于合成其他语言(例如 es-ES)的语音。
此代码示例演示了如何配置 SynthesizeRequest 以使用 en-US 语音克隆密钥合成 es-ES:
voice_clone_params = texttospeech.VoiceCloneParams( voice_cloning_key=en_us_voice_cloning_key ) request = texttospeech.SynthesizeSpeechRequest( input=texttospeech.SynthesisInput(text=transcript), voice=texttospeech.VoiceSelectionParams( language_code='es-ES', voice_clone=voice_clone_params ), audio_config=texttospeech.AudioConfig( audio_encoding=texttospeech.AudioEncoding.LINEAR16, sample_rate_hertz=24000, ), ) 使用 en-US 声音克隆密钥配置 StreamingSynthesizeConfig 以合成 es-ES 的示例:
voice_clone_params = texttospeech.VoiceCloneParams( voice_cloning_key=en_us_voice_cloning_key ) streaming_config = texttospeech.StreamingSynthesizeConfig( voice=texttospeech.VoiceSelectionParams( language_code='es-ES', voice_clone=voice_clone_params ), streaming_audio_config=texttospeech.StreamingAudioConfig( audio_encoding=texttospeech.AudioEncoding.PCM, sample_rate_hertz=24000, ), )