設定 Speech-to-Text

Speech-to-Text 是採用 Google 人工智慧 (AI) 技術的 API。您將音訊資料傳送至 Speech-to-Text,然後接收音訊資料的文字轉錄回應。

如要進一步瞭解如何建構語音轉文字要求,請參閱「要求」頁面。

總覽

您必須先在 Google Cloud 控制台中啟用 API,才能開始傳送要求給 Speech-to-Text。本頁的步驟會逐步說明下列操作:

  • 在專案中啟用 Speech-to-Text。
  • 請確認已為 Speech-to-Text 啟用計費功能。
  • (選用) 建立新的 Google Cloud Storage 值區,用於儲存音訊資料。

事前準備

您可以透過 REST API 或語音轉文字控制台存取這項服務。我們提供程式碼範例,說明如何向 REST API 提出要求並接收回應。您可以按照 Speech-to-Text 快速入門使用指南,瞭解如何使用這些範例。如果您想使用 Speech-to-Text,但不想撰寫太多程式碼,可以使用 Cloud Speech-to-Text 控制台

本指南將逐步說明如何開始傳送要求至 REST API。如果您是初學程式設計,建議您先參閱 Google Cloud Platform 主控台內的逐步教學課程,再開始本快速入門課程。

設定 Speech-to-Text 的 Google Cloud 專案

  1. 登入 Google Cloud 控制台

  2. 前往專案選取器頁面

    您可以選擇現有專案,或建立新專案。如要進一步瞭解如何建立專案,請參閱「建立及管理專案」。

  3. 如果您建立新專案,系統會提示您將帳單帳戶連結至該專案。如果您使用的是現有專案,請確認已啟用帳單服務。

    瞭解如何確認您已啟用專案的計費功能

  4. 選取專案並連結至帳單帳戶後,即可啟用 Speech-to-Text API。前往頁面頂端的「搜尋產品和資源」列,然後輸入「speech」。從結果清單中選取「Cloud Speech-to-Text API」

  5. 如要試用 Speech-to-Text 而不連結至專案,請選擇「TRY THIS API」選項。如要啟用 Speech-to-Text API 以便在專案中使用,請按一下「啟用」

  6. (選用) 啟用資料記錄功能。選擇啟用資料記錄功能,即表示您允許 Google 錄製您傳送至 Speech-to-Text 的所有音訊資料。這些資料會用於改善語音轉文字模型。選擇啟用資料記錄功能的使用者,可享較低的價格。詳情請參閱定價和資料記錄條款及細則頁面。

選用:建立 Cloud Storage 值區

如果要轉錄的音訊長度超過 60 秒或檔案大小超過 10 MB,您必須先將音訊資料儲存在 Cloud Storage 儲存桶中,才能使用 Speech-to-Text 轉錄。請按照下列步驟建立新的 bucket。

  • In the Google Cloud console, go to the Cloud Storage Buckets page.

    Go to Buckets

  • Click Create.
  • On the Create a bucket page, enter your bucket information. To go to the next step, click Continue.
    1. For Name your bucket, enter a unique bucket name. Don't include sensitive information in the bucket name, because the bucket namespace is global and publicly visible.
    2. In the Choose where to store your data section, do the following:
      1. Select a Location type.
      2. Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
      3. To set up cross-bucket replication, select Add cross-bucket replication via Storage Transfer Service and follow these steps:

        Set up cross-bucket replication

        1. In the Bucket menu, select a bucket.
        2. In the Replication settings section, click Configure to configure settings for the replication job.

          The Configure cross-bucket replication pane appears.

          • To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
          • To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
          • Click Done.
    3. In the Choose how to store your data section, do the following:
      1. Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
      2. To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
    4. In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
    5. In the Choose how to protect object data section, do the following:
      • Select any of the options under Data protection that you want to set for your bucket.
        • To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
        • To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
        • To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
          • To enable Object Retention Lock, click the Enable object retention checkbox.
          • To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
      • To choose how your object data will be encrypted, expand the Data encryption section (), and select a Data encryption method.
  • Click Create.
  • 停用 Speech-to-Text API

    如果您日後不再需要使用 Speech-to-Text API,請完成下列步驟。

    1. 前往 Google Cloud 資訊主頁,然後點選「API」方塊中的「前往 API 總覽」連結。
    2. 選取「Cloud Speech-to-Text API」
    3. 按一下 Cloud Speech-to-Text API 頁面頂端的「DISABLE API」按鈕。

    後續步驟

    瞭解如何使用用戶端程式庫gcloud指令列Speech-to-Text UI,將轉錄要求傳送至 Speech-to-Text API。