Skip to main content
Open In ColabOpen on GitHub

Google Cloud 文字转语音

Google Cloud Text-to-Speech enables developers to synthesize natural-sounding speech with 100+ voices, available in multiple languages and variants. It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks to deliver the highest fidelity possible.

It supports multiple languages, including English, German, Polish, Spanish, Italian, French, Portuguese, and Hindi.

本笔记本展示了如何与Google Cloud Text-to-Speech API交互以实现语音合成功能。

首先,您需要设置一个 Google Cloud 项目。您可以按照此处的说明进行操作。

!pip install --upgrade langchain-google-community[texttospeech]

实例化

from langchain_google_community import TextToSpeechTool
API 参考:TextToSpeechTool

已弃用的 GoogleCloudTextToSpeechTool

from langchain_community.tools import GoogleCloudTextToSpeechTool
text_to_speak = "Hello world!"

tts = GoogleCloudTextToSpeechTool()
tts.name

我们可以生成音频,将其保存到临时文件,然后播放它。

speech_file = tts.run(text_to_speak)