求助:Google Cloud Speech-to-Text服务账户密钥查找与环境变量设置
Hey Carol, totally get where you're coming from—Google Cloud's setup can feel a bit opaque when you're not deep in code, but let's break this down step by step, no jargon required.
Step 1: Download the Service Account Key JSON File
Here's how to grab that crucial JSON file from the Google Cloud Console:
- Open the Google Cloud Console and select the project you already created.
- Use the top search bar to find IAM & Admin, then click into the Service Accounts page.
- Click the Create Service Account button at the top. Give it a simple name (like
speech-to-text-service) and a quick description so you remember its purpose, then hit Create and Continue. - Next, grant this service account permission to use the Speech-to-Text API. In the "Select a role" dropdown, search for and select either Cloud Speech-to-Text Client (basic access) or Cloud Speech-to-Text Admin (full access). Click Continue.
- Skip the third step (adding users to the service account) and click Done to return to the service accounts list.
- Find the service account you just created, click its name to open the details page.
- Switch to the Keys tab, then click Add Key > Create new key.
- Make sure the key type is set to JSON, then click Create. Your browser will automatically download the JSON file—save it somewhere easy to find, like your Documents folder.
Step 2: Set the GOOGLE_APPLICATION_CREDENTIALS Environment Variable
This tells Google's tools where to find your key file. The steps vary a bit by operating system:
Windows
- Press
Win + R, typesysdm.cpl, and hit Enter to open the System Properties window. - Go to the Advanced tab, then click Environment Variables.
- Under either "User variables" (only applies to your account) or "System variables" (applies to all users), click New.
- For Variable name, enter
GOOGLE_APPLICATION_CREDENTIALS. - For Variable value, paste the full path to your downloaded JSON file (e.g.,
C:\Users\YourName\Documents\my-speech-key.json). - Click OK on all open windows to save changes. Restart any command prompts or apps you're using for the variable to take effect.
Mac/Linux
Open your terminal app.
If you use Bash (most Linux systems or older Macs), edit your profile file with:
nano ~/.bash_profileAdd this line (replace the path with your actual JSON file location):
export GOOGLE_APPLICATION_CREDENTIALS="/Users/YourName/Documents/my-speech-key.json"Save the file (Ctrl+O, then Enter) and exit (Ctrl+X), then run
source ~/.bash_profileto apply changes immediately.If you use Zsh (default on new Macs), edit your Zsh config instead:
nano ~/.zshrcAdd the same
exportline as above, save, exit, then runsource ~/.zshrc.
Quick Tip
Double-check the file path you enter—if there are spaces in the path, wrap it in quotes (like the examples above) to avoid errors.
内容的提问来源于stack exchange,提问作者Carol Leigh

