Speech: 403 Request had insufficient authentication scopes.
See original GitHub issueSee #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:
- Created 6 years ago
- Comments:6 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
replace this line:
with this:
and if you did not pass, delete (token.json) folder and try again