Create an API key

Підтвердити виконання

/ 25

Make an entity analysis request and call Natural Language API

Підтвердити виконання

/ 25

Create a Speech API request and call Speech API

Підтвердити виконання

/ 25

Sentiment analysis with the Natural Language API

Підтвердити виконання

/ 25

This lab may incorporate AI tools to support your learning.
This content is not yet optimized for mobile devices.
For the best experience, please visit us on a desktop computer using a link sent by email.

ARC114

Google Cloud self-paced labs

Overview

In a challenge lab you’re given a scenario and a set of tasks. Instead of following step-by-step instructions, you will use the skills learned from the labs in the course to figure out how to complete the tasks on your own! An automated scoring system (shown on this page) will provide feedback on whether you have completed your tasks correctly.

When you take a challenge lab, you will not be taught new Google Cloud concepts. You are expected to extend your learned skills, like changing default values and reading and researching error messages to fix your own mistakes.

To score 100% you must successfully complete all tasks within the time period!

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

Challenge scenario

You are starting your career as a junior cloud architect. In this role, you have been assigned to work on a team project that requires you to use the Cloud Natural Language API and Cloud Speech API services in Google Cloud.

You are expected to have the skills and knowledge to complete the tasks that follow.

Your challenge

For this challenge, you are asked to analyze text and speech using the Cloud Natural Language API and Cloud Speech-to-Text API, respectively. You also need to perform sentiment analysis on a text document using Python in Google Cloud Shell.

You need to:

  • Create an API key
  • Make an entity analysis request and call the Natural Language API
  • Create a speech analysis request and call the Speech API
  • Analyze sentiment with the Natural Language API

Each task is described in detail below. Good luck!

Task 1. Create an API key

  1. In the Google Cloud console, navigate to Navigation menu > APIs & Services > Credentials.

  2. Click Create Credentials at the top of the screen and select API key.

  3. Save the generated API key to an environment variable in Cloud Shell:

    export API_KEY="<YOUR_API_KEY>"

Click Check my progress to verify the objective. Create an API key

Task 2. Make an entity analysis request and call the Natural Language API

  1. In the Google Cloud console, click Activate Cloud Shell (>_).

  2. Set your Google Cloud Project ID and Storage bucket environment variables:

    export GOOGLE_CLOUD_PROJECT=$(gcloud config get-value project) export BUCKET_NAME="${GOOGLE_CLOUD_PROJECT}-speech-nlp"
  3. Next, create a JSON file named nl_request.json which you will pass to the Natural Language API for analysis. You can add the following code to your JSON file to analyze text about the city of Boston or, alternatively, add text of your own choosing to the content object to perform entity analysis on that instead.

{ "document":{ "type":"PLAIN_TEXT", "content":"With approximately 8.2 million people residing in Boston, the capital city of Massachusetts is one of the largest in the United States." }, "encodingType":"UTF8" }
  1. You can now pass your request body, along with the API key environment variable you saved earlier, to the Natural Language API using the curl command:
curl "https://language.googleapis.com/v1/documents:analyzeEntities?key=${API_KEY}" \ -s -X POST -H "Content-Type: application/json" --data-binary @nl_request.json > nl_response.json
  1. Upload the request and response files to your Cloud Storage bucket to verify your progress:
gcloud storage cp nl_request.json gs://${BUCKET_NAME}/nl_request.json gcloud storage cp nl_response.json gs://${BUCKET_NAME}/nl_response.json

Click Check my progress to verify the objective. Make an entity analysis request and call the Natural Language API

Task 3. Create a speech analysis request and call the Speech API

Note: For this task, you will use a pre-recorded file that's available on Cloud Storage: gs://cloud-samples-tests/speech/brooklyn.flac. Listen to the audio file before sending it to the Speech API.
  1. In Cloud Shell, create another JSON file named speech_request.json for this task, and configure it with the URI of the sample audio file in Cloud Storage:
{ "config": { "encoding":"FLAC", "languageCode": "en-US" }, "audio": { "uri":"gs://cloud-samples-tests/speech/brooklyn.flac" } }
  1. Pass your request body, along with the API key environment variable, to the Speech-to-Text API using curl:
curl "https://speech.googleapis.com/v1/speech:recognize?key=${API_KEY}" \ -s -X POST -H "Content-Type: application/json" --data-binary @speech_request.json > speech_response.json
  1. Upload the request and response files to your Cloud Storage bucket to verify your progress:
gcloud storage cp speech_request.json gs://${BUCKET_NAME}/speech_request.json gcloud storage cp speech_response.json gs://${BUCKET_NAME}/speech_response.json

Click Check my progress to verify the objective. Create a speech analysis request and call the Speech API

Task 4. Analyze sentiment with the Natural Language API

For this task, you need to analyze text sentiment using the Google Cloud Natural Language API client library in Python, which determines the overall attitude (positive or negative) of a content sample such as a movie review.

  1. In Cloud Shell, copy the starter Python application script sentiment_analysis.py from your Cloud Storage bucket:

    gcloud storage cp gs://${BUCKET_NAME}/sentiment_analysis.py .
  2. Download the fictitious movie review samples from Google Cloud Storage and extract the archive:

    gcloud storage cp gs://cloud-samples-tests/natural-language/sentiment-samples.tgz . tar -xzvf sentiment-samples.tgz
  3. Open sentiment_analysis.py in your preferred editor (or Cloud Shell Editor) and complete the analyze(movie_review_filename) function using Python:

    • Instantiate a LanguageServiceClient instance.
    • Read the review file into a variable.
    • Instantiate a Document object with the file's text content.
    • Call client.analyze_sentiment with the document and print the results with print_result(response).
  4. Run your sentiment analysis on reviews/bladerunner-pos.txt and save the output:

    python3 sentiment_analysis.py reviews/bladerunner-pos.txt > sentiment_response.txt
  5. Upload the sentiment analysis response to your Cloud Storage bucket:

    gcloud storage cp sentiment_response.txt gs://${BUCKET_NAME}/sentiment_response.txt

Click Check my progress to verify the objective. Analyze sentiment with the Natural Language API

Congratulations!

Analyze Speech & Language with Google APIs skill badge

You have successfully performed entity and sentiment analysis on text as well as speech using the Natural Language and Speech APIs.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated October 19, 2026

Lab Last Tested October 19, 2026

Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We can notify you via email when it becomes available

Great!

We can contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Using an Incognito or private browser window is the best way to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.