Speech-to-Text V2 支援名為「辨識器」 Google Cloud 的資源。辨識器代表儲存且可重複使用的辨識設定。您可以運用這些標籤,將應用程式的轉錄內容或流量歸類為邏輯群組。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往「IAM」頁面 - 選取專案。
- 按一下「授予存取權」 。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
Install the Google Cloud CLI.
-
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Speech-to-Text APIs.
-
Make sure that you have the following role or roles on the project: Cloud Speech Administrator
Check for the roles
-
In the Google Cloud console, go to the IAM page.
Go to IAM - Select the project.
-
In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.
- For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.
Grant the roles
-
In the Google Cloud console, go to the IAM page.
前往「IAM」頁面 - 選取專案。
- 按一下「授予存取權」 。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
Install the Google Cloud CLI.
-
-
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
-
To initialize the gcloud CLI, run the following command:
gcloud init
-
If you're using a local shell, then create local authentication credentials for your user account:
gcloud auth application-default login
You don't need to do this if you're using Cloud Shell.
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.
-
Optional: Revoke the authentication credentials that you created, and delete the local credential file.
gcloud auth application-default revoke
-
Optional: Revoke credentials from the gcloud CLI.
gcloud auth revoke
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
用戶端程式庫可以使用應用程式預設憑證,輕鬆向 Google API 進行驗證,然後傳送要求給這些 API。使用應用程式預設憑證,您可以在本機測試及部署應用程式,不必變更基礎程式碼。詳情請參閱「 驗證以使用用戶端程式庫」。
此外,請確認您已安裝用戶端程式庫。
瞭解辨識器
辨識器是可設定、可重複使用的辨識設定。使用常用的辨識設定建立辨識器,有助於簡化辨識要求並縮減大小。
辨識工具的核心元素是預設設定。這是這項辨識工具執行的每項辨識要求的設定。您可以根據個別要求覆寫這項預設值。針對特定辨識工具的要求,保留所需功能的預設設定,同時覆寫特定要求中的特定功能。
盡可能重複使用辨識器。為每個要求建立一個工作階段,會大幅增加應用程式的延遲時間,並耗用資源配額。在整合和設定期間,請盡量不要建立這些項目,然後重複用於辨識要求。
建立辨識器
以下範例說明如何建立辨識器,用來傳送辨識要求:
Python
使用現有辨識器傳送要求
以下是使用相同辨識器傳送多個辨識要求的範例:
Python
在辨識器中啟用功能
辨識器可用於啟用辨識功能中的各種功能,例如自動加上標點符號或過濾不雅用語。
以下範例說明如何在辨識工具中啟用自動標點符號功能,以便在透過這個辨識工具提出的辨識要求中啟用自動標點符號功能:
Python
在辨識要求中覆寫辨識器功能
以下範例說明如何在辨識器中啟用多項功能,但針對這項辨識要求停用自動標點符號:
Python
傳送不含辨識器的要求
辨識要求中的辨識器為選用項目。如要在沒有辨識器的情況下提出要求,只要在提出要求的位置使用辨識器資源 ID _
即可。範例如下:
Python
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
控制台
gcloud
Delete a Google Cloud project:
gcloud projects delete PROJECT_ID