Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ysaito8015/90a07f737aae58bcfec91de35570d999 to your computer and use it in GitHub Desktop.
Save ysaito8015/90a07f737aae58bcfec91de35570d999 to your computer and use it in GitHub Desktop.
Task 04 at GSP323 https://google.qwiklabs.com/focuses/11044 version (Lab Last Tested May 13, 2020)

Natural language

gcloud iam service-accounts create my-natlang-sa \
  --display-name "my natural language service account"
gcloud iam service-accounts keys create ~/key.json \
  --iam-account my-natlang-sa@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com
export GOOGLE_APPLICATION_CREDENTIALS="/home/USER/key.json"
gcloud ml language analyze-entities \
        --content="Old Norse texts portray Odin as one-eyed and long-bearded, frequently wielding a spear named Gungnir and wearing a cloak and a broad hat." > result.json
gsutil cp result.json gs://<YOUR_PROJECT>/task4-cnl.result

Cloud Speech:

Create an API key and export API_KEY variable in cloud shell. Create the file request.json with:

{
  "config": {
      "encoding":"FLAC",
      "languageCode": "en-US"
  },
  "audio": {
      "uri":"gs://cloud-training/gsp323/task4.flac"
  }
}
curl -s -X POST -H "Content-Type: application/json" \
    --data-binary @request.json \
    "https://speech.googleapis.com/v1/speech:recognize?key=${API_KEY}" > result.json
gsutil cp result.json gs://YOUR_PROJECT/task4-gcs.result

Video Intelligence:

gcloud iam service-accounts create quickstart
gcloud iam service-accounts keys create key.json --iam-account quickstart@${GOOGLE_CLOUD_PROJECT}.iam.gserviceaccount.com
gcloud auth activate-service-account --key-file key.json
export ACCESS_TOKEN=$(gcloud auth print-access-token)
vim response.json
{
   "inputUri":"gs://spls/gsp154/video/chicago.mp4",
   "features": [
       "TEXT_DETECTION"
   ]
}
curl -s -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $ACCESS_TOKEN" \
    'https://videointelligence.googleapis.com/v1/videos:annotate' \
    -d @response.json

// You will receive the operation name in the output, you will need it new step.

curl -s -H 'Content-Type: application/json' \
    -H "Authorization: Bearer $ACCESS_TOKEN" \
    'https://videointelligence.googleapis.com/v1/operations/<OPERATION_FROM_PREVIOUS_REQUEST>'
    // Replace your operation name here which you saved in above step.
gsutil cp result.json gs://YOUR_PROJECT/task4-gvi.result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment