question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Speech: 403 Request had insufficient authentication scopes.

See original GitHub issue

See #3212 for more information

Getting the same error and also it gave me 403 request error. google.api_core.exceptions.PermissionDenied: 403 Request had insufficient authentication scopes.

Note: Google SPeech API is enabled and I am using Python 3.6

Here is the code, thank you for your help.

 import argparse
 import io

 from google.oauth2 import service_account

 scope = 'https://www.googleapis.com/auth/drive'
 credentials = service_account.Credentials.from_service_account_file('Speech2Text-
 71ae27307424.json',scopes=(scope,))

 def transcribe_file_with_word_time_offsets(speech_file):
     """Transcribe the given audio file synchronously and output the word time
     offsets."""
     print("Start")
    
     from google.cloud import speech
     from google.cloud.speech import enums
     from google.cloud.speech import types   
    
     print("checking credentials")
    
     client = speech.SpeechClient(credentials=credentials)

     print("Checked")
     with io.open(speech_file, 'rb') as audio_file:
          content = audio_file.read()
        
     print("audio file read")    
    
     audio = types.RecognitionAudio(content=content)
    
     print("config start")
     config = types.RecognitionConfig(
             encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
             sample_rate_hertz=16000,
             language_code='en-US',
             enable_word_time_offsets=True)
    
     print("Recognizing:")
     response = client.recognize(config, audio) ## MAJOR PROBLEM
     print("Recognized")
 
     for result in response.results:
         alternative = result.alternatives[0]
         print('Transcript: {}'.format(alternative.transcript))
 
         for word_info in alternative.words:
             word = word_info.word
             start_time = word_info.start_time
             end_time = word_info.end_time
             print('Word: {}, start_time: {}, end_time: {}'.format(
                 word,
                 start_time.seconds + start_time.nanos * 1e-9,
                 end_time.seconds + end_time.nanos * 1e-9))
 
 def transcribe_gcs_with_word_time_offsets(gcs_uri):
     """Transcribe the given audio file asynchronously and output the word time
     offsets."""
     from google.cloud import speech
     from google.cloud.speech import enums
     from google.cloud.speech import types
     client = speech.SpeechClient()
 
     audio = types.RecognitionAudio(uri=gcs_uri)
     config = types.RecognitionConfig(
         encoding=enums.RecognitionConfig.AudioEncoding.FLAC,
         sample_rate_hertz=16000,
         language_code='en-US',
         enable_word_time_offsets=True)
 
     operation = client.long_running_recognize(config, audio)
 
     print('Waiting for operation to complete...')
     result = operation.result(timeout=90)
 
     for result in result.results:
         alternative = result.alternatives[0]
         print('Transcript: {}'.format(alternative.transcript))
         print('Confidence: {}'.format(alternative.confidence))
 
         for word_info in alternative.words:
             word = word_info.word
             start_time = word_info.start_time
             end_time = word_info.end_time
             print('Word: {}, start_time: {}, end_time: {}'.format(
                 word,
                 start_time.seconds + start_time.nanos * 1e-9,
                 end_time.seconds + end_time.nanos * 1e-9))

 if __name__ == '__main__':
     parser = argparse.ArgumentParser(description=__doc__,
         formatter_class=argparse.RawDescriptionHelpFormatter)
     parser.add_argument(dest='path', help='File or GCS path for audio file to be recognized')
     args = parser.parse_args()
     if args.path.startswith('gs://'):
         transcribe_gcs_with_word_time_offsets(args.path)
     else:
         transcribe_file_with_word_time_offsets(args.path)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
theacodescommented, Mar 8, 2018

You can’t use the drive scope to access Cloud Speech, you need to use to google-cloud-platform scope, or just leave scope unspecified and the library will handle it.

1reaction
aliallamycommented, Sep 26, 2019

replace this line:

static string[] Scopes = { SheetsService.Scope.Spreadsheets.ReadOnly };

with this:

static string[] Scopes = { SheetsService.Scope.Spreadsheets };

and if you did not pass, delete (token.json) folder and try again

Read more comments on GitHub >

github_iconTop Results From Across the Web

403 Request had insufficient authentication scopes - Stack ...
As you are on a GCE instance try setting the access scopes for the instance to 'Allow full access to all Cloud APIs'...
Read more >
Error : 403 Request had insufficient authentication scopes
Hello, If the email you are using is a managing user and does not have direct access to the client customer, you must...
Read more >
How To Fix The 403:Insufficient Authentication Scopes Error ...
The insufficient authentication scopes is an error in the OAuth 2.0 token provided in the request specifies scopes that are insufficient for accessing...
Read more >
Access the Secret Manager API - Google Cloud
If you receive an error with the following message, it means the instance or node was not provisioned with the correct OAuth scopes....
Read more >
Getting 403 error while calling the GA API analyticsdata ...
Based on your error, it seems that your access token had insufficient authentication scope. Please make sure that you have the required scopes...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found