I am a beginner trying to perform some Speech-to-Text as an experiment. I am new to Google Cloud API, and I am getting stuck at the Credential Authentication.
I have used this code to try to transcribe a 20 min long audio file to text. I am using Google Colaboratory for this.
My code is simply the imports, a code block for adding the JSON file to the env path, the function in the link, and a code block executing the function with the file path to the .wav file. I haven't edited the code, just copied it and used the same type of audio file they use (.wav).
I have followed the instructions here to get the JSON file for authorization.
To set an environment variable for GOOGLE_APPLICATION_CREDENTIALS
I inserted a code block before the function like so:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]='folder_path\\My First Project-##########.json'
This raised no errors so I assume that the credentials are added to the path. However, when I execute the function like so:
sample_long_running_recognize('folder_path\\audio_file.wav')
I get the error:
DefaultCredentialsError: File folder_path\\My First Project-##########.json was not found.
From the same 'Getting started with Authentication' link I have shared above, there is a function implicit()
given to test whether the authentication is done correctly. I defined the function and ran it, and I got the same error. What exactly am I doing wrong? I also ran set GOOGLE_APPLICATION_CREDENTIALS=folder_path\\My First Project-##########.json
in cmd as the instructions say. It didn't return any error there either. So why does it say the file is not found?
I have re-checked multiple times, there isn't an issue with the filepath, I have simply copied it and added double backslashes (this was due to the error SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
)
I solved that problem setting the GOOGLE_APPLICATION_CREDENTIALS
directly in the project folder and removing the quotes of the PATH
, just run this on your prompt
set GOOGLE_APPLICATION_CREDENTIALS=C:\Users\yourUser\credentials-file.json
without any quotes