使用用戶端程式庫從文字建立音訊
本快速入門導覽課程會逐步說明如何使用用戶端程式庫向 Text-to-Speech 提出要求,從文字建立音訊。
如要進一步瞭解 Text-to-Speech 的基本概念,請參閱「Text-to-Speech 基礎」。如要查看您的語言支援哪些合成語音,請參閱支援的語音和語言頁面。
事前準備
您必須先完成下列動作,才能向 Text-to-Speech API 傳送要求。詳情請參閱「事前準備」頁面。
- 在 Google Cloud 專案中啟用 Text-to-Speech。
- 確認已啟用 Text-to-Speech 的計費功能。
-
After installing the Google Cloud CLI, sign in to the gcloud CLI with your federated identity and then initialize it by running the following command:
gcloud init
-
Create local authentication credentials for your user account:
gcloud auth application-default login
If an authentication error is returned, and you are using an external identity provider (IdP), confirm that you have signed in to the gcloud CLI with your federated identity.
安裝用戶端程式庫
Go
go get cloud.google.com/go/texttospeech/apiv1
Java
If you are using Maven, add
the following to your pom.xml
file. For more information about
BOMs, see The Google Cloud Platform Libraries BOM.
If you are using Gradle, add the following to your dependencies:
If you are using sbt, add the following to your dependencies:
If you're using Visual Studio Code, IntelliJ, or Eclipse, you can add client libraries to your project using the following IDE plugins:
The plugins provide additional functionality, such as key management for service accounts. Refer to each plugin's documentation for details.
Node.js
安裝程式庫前,請確認您已設定適當的 Node.js 開發環境。
npm install @google-cloud/text-to-speech
Python
安裝程式庫前,請確認您已設定適當的 Python 開發環境。
pip install --upgrade google-cloud-texttospeech
其他語言
C#: 請按照用戶端程式庫頁面上的 C# 設定說明操作, 然後前往 .NET 適用的 Text-to-Speech 參考說明文件。
PHP: 請按照用戶端程式庫頁面上的 PHP 設定說明 操作,然後前往 PHP 適用的 Text-to-Speech 參考文件。
Ruby: 請按照用戶端程式庫頁面的 Ruby 設定說明 操作,然後前往 Ruby 適用的 Text-to-Speech 參考說明文件。
建立音訊資料
現在您可以使用 Text-to-Speech 建立合成人類語音的音訊檔。使用下列程式碼,將 synthesize
要求傳送至 Text-to-Speech API。
恭喜!您已將第一個要求傳送至 Text-to-Speech。
還順利嗎?
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
- 請透過 Google Cloud console 刪除不需要的專案。
後續步驟