本頁說明如何在 Speech-to-Text 中設定加密金鑰,加密 Speech-to-Text 資源。
Speech-to-Text 可讓您提供 Cloud Key Management Service 加密金鑰,並使用提供的金鑰加密資料。如要進一步瞭解加密功能,請參閱加密頁面。
事前準備
- 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.
-
Verify 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.
前往「身分與存取權管理」頁面 - 選取專案。
- 按一下 「授予存取權」。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
Install the Google Cloud CLI.
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
如要初始化 gcloud CLI,請執行下列指令:
gcloud init
-
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Verify 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.
前往「身分與存取權管理」頁面 - 選取專案。
- 按一下 「授予存取權」。
-
在「New principals」(新增主體) 欄位中,輸入您的使用者 ID。 這通常是 Google 帳戶的電子郵件地址。
- 在「Select a role」(選取角色) 清單中,選取角色。
- 如要授予其他角色,請按一下 「新增其他角色」,然後新增每個其他角色。
- 按一下 [Save]。
Install the Google Cloud CLI.
如果您使用外部識別資訊提供者 (IdP),請先 使用聯合身分登入 gcloud CLI。
如要初始化 gcloud CLI,請執行下列指令:
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.
- 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.
- 如要進一步瞭解在 Speech-to-Text 中指定加密金鑰時加密的內容,請參閱這篇文章。
- 瞭解如何轉錄串流音訊。
- 瞭解如何轉錄長音訊檔案。
- 練習轉錄短音訊檔案。
- 如要獲得最佳效能、準確率與其他提示,請參閱最佳做法說明文件。
用戶端程式庫可以使用應用程式預設憑證,輕鬆向 Google API 進行驗證,然後傳送要求給這些 API。使用應用程式預設憑證,您可以在本機測試及部署應用程式,不必變更基礎程式碼。詳情請參閱「 驗證以使用用戶端程式庫」。
此外,請確認您已安裝用戶端程式庫。
啟用 Cloud Key Management Service 金鑰的存取權
Speech-to-Text 會使用服務帳戶存取 Cloud KMS 金鑰。依預設,服務帳戶無法存取 Cloud KMS 金鑰。
服務帳戶電子郵件地址如下:
service-PROJECT_NUMBER@gcp-sa-speech.iam.gserviceaccount.com
如要使用 Cloud KMS 金鑰加密 Speech-to-Text 資源,請為這個服務帳戶指派 roles/cloudkms.cryptoKeyEncrypterDecrypter
角色:
gcloud projects add-iam-policy-binding PROJECT_NUMBER \
--member=serviceAccount:service-PROJECT_NUMBER@gcp-sa-speech.iam.gserviceaccount.com \
--role=roles/cloudkms.cryptoKeyEncrypterDecrypter
如要進一步瞭解專案 IAM 政策,請參閱「管理專案、資料夾和機構的存取權」一文。
如要進一步瞭解如何管理 Cloud Storage 存取權,請參閱 Cloud Storage 說明文件中的「建立及管理存取權控管清單」。
指定加密金鑰
以下範例說明如何使用 Config
資源,將加密金鑰提供給 Speech-to-Text:
Python
在專案的 [Config
] 資源中指定加密金鑰後,在相應位置建立的任何新資源都會使用這個金鑰加密。如要進一步瞭解加密內容和時間,請參閱加密頁面。
加密資源的 kms_key_name
和 kms_key_version_name
欄位會填入 Speech-to-Text API 回應。
移除加密措施
如要避免日後資源使用加密金鑰加密,請使用上述程式碼,並在要求中提供空字串 (""
) 做為金鑰。這樣可確保新資源不會加密。這項指令不會解密現有資源。
金鑰輪替和刪除
金鑰輪替後,以舊版 Cloud KMS 金鑰加密的資源仍會以該版本加密。金鑰輪替後建立的任何資源,都會使用新的預設金鑰版本加密。金鑰輪替後,使用 Update*
方法更新的任何資源,都會以新的預設金鑰版本重新加密。
刪除金鑰後,語音轉文字服務就無法解密資料,也無法建立資源,或存取以已刪除金鑰加密的資源。同樣地,如果撤銷金鑰的語音轉文字權限,語音轉文字就無法解密您的資料,也無法建立或存取以撤銷語音轉文字權限的金鑰加密的資源。
重新加密資料
如要重新加密資源,請在更新 Config
資源中的金鑰規格後,為每個資源呼叫對應的 Update*
方法。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取本頁所用資源的費用,請按照下列步驟操作。
控制台
gcloud