嘗試 Running Google Cloud Speech-to-Text Service on Colab

Ask for help in Stackoverflow

Figure 1:\colon Ask problem of calling google cloud speech api in colab on stackoverflow


Figure 1:\colon fail on type gcloud init on colab

圖一呈現colab上實際下command code遇到的問題。

[牧民瑩婷說試試!gcloud init -1]

Automate gcloud init

曾經在StackOverflow看到有人發問[1]

Q:\colon
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:\colon
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:\colon

  1. Select configuration (one of the following)
    • gcloud config configurations create [my_configuration]
    • gcloud config configurations activate [my_configuration]
  2. Setup credentials (one of the following)
    • (interactive) gcloud auth login
    • gcloud config set account [my_existing_credentials]`
    • gcloud auth activate-service-account [account-service]
  3. Set Project
    • gcloud config set project [my_project]
      • List of accessible projects for set credentials can be seen via gcloud projects list
  4. (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
  5. (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 via gcloud compute regions list
  6. (Optional) create default config file for gsutil
    • gsutil config -n -o ~/.boto


Figure 2:\colon alternative method of gcloud init

Figure 3:\colon permission denied of alternative method

可正常執行

原因:\colon

!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 :\colon 成功從Colab呼叫使用google cloud speech-to-text api

[1]
https://stackoverflow.com/questions/42379685/can-i-automate-google-cloud-sdk-gcloud-init-interactive-command

[2] https://blog.hoyo.idv.tw/?p=4544

[3] https://stackoverflow.com/questions/45501082/set-google-application-credentials-in-python-project-to-use-google-api

results matching ""

    No results matching ""