Reputation: 63
I want to implement a text-to-speech function for my application using Python. However, I got this error after following a tutorial here https://cloud.google.com/text-to-speech/docs/reference/libraries.
Traceback (most recent call last):
File "tts.py", line 3, in <module>
client = texttospeech.TextToSpeechClient()
File "/usr/local/lib/python2.7/dist-packages/google/cloud/texttospeech_v1/gapic/text_to_speech_client.py", line 84, in __init__
scopes=self._DEFAULT_SCOPES,
File "/usr/local/lib/python2.7/dist-packages/google/api_core/grpc_helpers.py", line 170, in create_channel
credentials, _ = google.auth.default(scopes=scopes)
File "/usr/local/lib/python2.7/dist-packages/google/auth/_default.py", line 306, in default
raise exceptions.DefaultCredentialsError(_HELP_MESSAGE)
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://developers.google.com/accounts/docs/application-default-credentials.
I've set the environment variable (GOOGLE_APPLICATION_CREDENTIALS) using this command in Terminal and I am positive that my credentials are working as I've tested on other Google Cloud services.
export GOOGLE_APPLICATION_CREDENTIALS="/home/pi/labs/test/google_credentials.json"
Here are some of the things that I've done but didn't manage to work still
Upvotes: 1
Views: 998
Reputation: 63
Never mind, I managed to solve it by adding these two lines on my code:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/home/pi/labs/test/google_credentials.json"
Upvotes: 4