Arcade Adventure: Google Cloud ML APIs | GSP119
Solution for Arcade Adventure: Google Cloud ML APIs | GSP119. 1 lab: GSP119. Fast copy-paste commands for Google Cloud.
GSP119 — Speech-to-Text API: Qwik Start
Estimated time: 10 minutes
# 🚀 Google Cloud Speech-to-Text API | GSP119 > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created for educational purposes, hands-on practice, and Google Cloud certification preparation. This guide is designed to help learners understand the Google Cloud Speech-to-Text API, API key configuration, JSON request payloads, Cloud Storage, and speech recognition workflows through practical exercises. Always attempt the lab yourself first and follow Google Cloud Skills Boos
clear
# Professional ANSI Color Variables
CYAN='\033[1;36m'
GREEN='\033[1;32m'
YELLOW='\033[1;33m'
BLUE='\033[1;34m'
RESET='\033[0m'
BOLD='\033[1m'
echo -e "${CYAN}${BOLD}"
echo " ____ _ _ _ __ ___ "
echo " / __ \ | | (_) | / _| / _ \ "
echo " | | | |_ __| |__ _| |_ ___ | |_ | | | |_ __ ___ "
echo " | | | | '__| '_ \| | __| / _ \ | _|| | | | '_ \ / __| "
echo " | |__| | | | |_) | | |_ | (_) || | | |_| | |_) \__ \ "
echo " \____/|_| |_.__/|_|\__| \___/ |_| \___/| .__/|___/ "
echo " | | "
echo " |_| "
echo -e "${RESET}"
export PROJECT_ID=$(gcloud config get-value project)
echo -e "${YELLOW}▶ Task 1: Creating API Key for Cloud Speech-to-Text API...${RESET}"
# Generating the key and applying the strict target restriction required by new lab policies
gcloud services api-keys create --display-name="Speech-Key" \
--api-target=service=speech.googleapis.com
# Give the API key a few seconds to propagate in the backend
sleep 5
export KEY_NAME=$(gcloud services api-keys list --filter="displayName=Speech-Key" --format="value(name)" | head -n 1)
export API_KEY=$(gcloud services api-keys get-key-string $KEY_NAME --format="value(keyString)")
echo -e "${BLUE}▶ Task 2: Building request.json payload...${RESET}"
cat > request.json <<EOF
{
"config": {
"encoding":"FLAC",
"languageCode": "en-US"
},
"audio": {
"uri":"gs://cloud-samples-tests/speech/brooklyn.flac"
}
}
EOF
echo -e "${YELLOW}▶ Task 3: Querying the Speech-to-Text API...${RESET}"
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
echo -e "${CYAN}▶ Displaying transcription results:${RESET}"
cat result.json
echo -e "\n${BLUE}▶ Uploading results to Cloud Storage...${RESET}"
# Creating the required bucket before attempting the upload
gcloud storage buckets create gs://$PROJECT_ID-speech/ --location=us
gcloud storage cp result.json gs://$PROJECT_ID-speech/
echo -e "${GREEN}✓ All tasks completed! You may now click 'Check my progress' on the lab page.${RESET}"