在 Raspbian 中为 Google Cloud Text to Speech 设置环境变量不起作用
Setting environment variables for Google Cloud Text to Speech in Raspbian doesn't work
我想使用 Python 为我的应用程序实现文本到语音的功能。但是,在按照此处 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.
我已经在终端中使用此命令设置了环境变量 (GOOGLE_APPLICATION_CREDENTIALS),并且我确信我的凭据在其他 Google 云服务上进行了测试。
export GOOGLE_APPLICATION_CREDENTIALS="/home/pi/labs/test/google_credentials.json"
以下是一些我已经完成但仍无法正常工作的事情
- 重新安装google-cloud-texttospeech
- Making credentials permanent
- 确保使用 env & set | 设置我的环境变量grep GOOGLE_APPLICATION_CREDENTIALS 在终端上检查
- 重新启动了我的 raspberry pi
没关系,我通过在我的代码中添加这两行设法解决了这个问题:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/home/pi/labs/test/google_credentials.json"
我想使用 Python 为我的应用程序实现文本到语音的功能。但是,在按照此处 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.
我已经在终端中使用此命令设置了环境变量 (GOOGLE_APPLICATION_CREDENTIALS),并且我确信我的凭据在其他 Google 云服务上进行了测试。
export GOOGLE_APPLICATION_CREDENTIALS="/home/pi/labs/test/google_credentials.json"
以下是一些我已经完成但仍无法正常工作的事情
- 重新安装google-cloud-texttospeech
- Making credentials permanent
- 确保使用 env & set | 设置我的环境变量grep GOOGLE_APPLICATION_CREDENTIALS 在终端上检查
- 重新启动了我的 raspberry pi
没关系,我通过在我的代码中添加这两行设法解决了这个问题:
import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="/home/pi/labs/test/google_credentials.json"