嘗試 Running Google Cloud Speech-to-Text Service on Colab
Ask for help in Stackoverflow
Figure 1 Ask problem of calling google cloud speech api in colab on stackoverflow
Figure 1 fail on type gcloud init
on colab
圖一呈現colab上實際下command code遇到的問題。
[牧民瑩婷說試試!gcloud init -1
]
Automate gcloud init
曾經在StackOverflow看到有人發問[1]
Q
Documentation on Google Cloud SDK directs one to run gcloud init
after installing it. Is there a way to automate this step given that gcloud init
is an interactive command.
A
You does not need to run gcloud init
. Main goal is to make sure credentials are configured and perhaps the project property is set. If you have service account credentials, gcloud can be configured and ready to go via
gcloud auth activate-service-account [service_account] --key-file=[crediential_key.json]
gcloud config set project [my-project]
For completeness gcloud init
essentially runs the following steps
- Select configuration (one of the following)
gcloud config configurations create [my_configuration]
gcloud config configurations activate [my_configuration]
- Setup credentials (one of the following)
- (interactive)
gcloud auth login
- gcloud config set account [my_existing_credentials]`
gcloud auth activate-service-account [account-service]
- (interactive)
- Set Project
gcloud config set project [my_project]
- List of accessible projects for set credentials can be seen via
gcloud projects list
- List of accessible projects for set credentials can be seen via
- (Optional) Set default GCE zone (Compute API must be enabled)
gcloud config set compute/zone [my_default_gce_zone]
- List of zones can be obtained via
gcloud compute zones list
- List of zones can be obtained via
- (Optional) Set default GCE region (Compute API must be enabled)
gcloud config set compute/region [my_default_gce_region]
*List of regions can be obtained viagcloud compute regions list
- (Optional) create default config file for
gsutil
gsutil config -n -o ~/.boto
Figure 2 alternative method of gcloud init
Figure 3 permission denied of alternative method
可正常執行
原因
!gcloud auth activate-service-account starting-account-e4whhkxv1a2x@gc-ai-challenge-1529370474866.iam.gserviceaccount.com --key-file=GC-AI-Challenge-4dc21e90cad0.json
根據[2],我們原本打的指令裡面[email protected]
是多餘的,只需要key
!gcloud auth activate-service-account --key-file=GC-AI-Challenge-4dc21e90cad0.json
key file裡面就有activate-service-account的資訊。
另外依照[3]的說明我們還要把!export GOOGLE_APPLICATION_CREDENTIALS="GC-AI-Challenge-4dc21e90cad0.json"
改成
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="GC-AI-Challenge-4dc21e90cad0.json"
不然會出現GOOGLE_APPLICATION_CREDENTIALS Error [要再截圖呈現]
Figure 成功從Colab呼叫使用google cloud speech-to-text api