1

I would like to test the Google Cloud Speech-to-Text API from within Firebase Emulators. I currently have a trigger set on Firebase Storage that automatically gets fired when I upload a file via the Emulator Storage UI. This makes a request to the Speech to Text API, but I keep getting a permission denied error, as follows:

Error: 7 PERMISSION_DENIED: Cloud Speech-to-Text API has not been used in project 563584335869 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/speech.googleapis.com/overview?project=563584335869 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.

I understand that project 563584335869 is the Firebase Cli project. I have set the following environment variables when starting the emulator:

export GCLOUD_PROJECT=my-actual-glcloud-project-id && export FIREBASE_AUTH_EMULATOR_HOST='localhost:9099' && export GOOGLE_APPLICATION_CREDENTIALS=./path/to/service-account.json &&
firebase emulators:start

The service_account.json key file is associated with a service_account that has the following roles, as demonstrated by running

gcloud projects get-iam-policy my_project_id --flatten="bindings[].members" --format='table(bindings.role)' --filter="bindings.members:serviceAccount:my_service_account@my_project_id.iam.gserviceaccount.com"
ROLE
roles/speech.admin
roles/storage.admin
roles/storage.objectAdmin
roles/storage.objectCreator
roles/storage.objectViewer

Since the credentials for the service account I am using should have admin access to the speech to text api, why do I keep getting a permission denied error when running from the emulator, and how can I fix it?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
CambodianCoder
  • 467
  • 4
  • 14

1 Answers1

3

The project id 563584335869 is not yours. It is firebase-cli cloud project’s project-id. In this case, the problem is arising because you have to set your own configuration using your credentials or your key.

You can see below a code for NodeJS which I found in github[1] where it shows how to configure your authentication to use the API.

// Imports the Google Cloud client library
const textToSpeech = require('@google-cloud/text-to-speech');

// Create the auth config
const config = {
  projectId: 'grape-spaceship-123',
  keyFilename: '/path/to/keyfile.json'
};

// Creates a client
const client = new textToSpeech.TextToSpeechClient(config);

[1]https://github.com/googleapis/nodejs-text-to-speech/issues/26

EDIT

There are different ways to set up your authentication for speech to text. One way to resolve this problem would be to add the same auth configuration as the Text-to-Speech and it should look something like this in your code.

// Imports the Google Cloud client library
const speech = require('@google-cloud/speech');

// Create the auth config
const authconfig = {
  projectId: 'grape-spaceship-123',
  keyFilename: '/path/to/keyfile.json'
};

// Creates a client
const client = new speech.SpeechClient(authconfig);

Another way to solve this problem according to this Google Cloud Documentation[2] is to setup your authentication.

[2]https://cloud.google.com/speech-to-text/docs/libraries#setting_up_authentication

Jose Gutierrez Paliza
  • 1,373
  • 1
  • 5
  • 12
  • Thanks for the link to Text-To-Speech documentation, but this question asks specifically about Google Speech to Text API. The sample config at https://github.com/googleapis/nodejs-speech#using-the-client-library offers no options to load a keyFilename. – CambodianCoder Oct 13 '21 at 08:13
  • @CambodianCoder I edited my answer let me know if this help you. – Jose Gutierrez Paliza Oct 13 '21 at 15:16