我目前正在使用Google云平台的语音到文本Api。我已经按照提示阅读了开发人员站点上的一些可能的错误和疑难解答信息。但我似乎无法创建访问auth凭据所需的env变量。你知道吗
变量的名称是GOOGLE\u APPLICATION\u CREDENTIALS。我尝试了以下方法:
set GOOGLE_APPLICATION_CREDENTIALS=[path]
$env:GOOGLE_APPLICATION_CREDENTIALS=[path]
def explicit():
from google.cloud import storage
# Explicitly use service account credentials by specifying the private key
# file.
storage_client = storage.Client.from_service_account_json(
'path')
# Make an authenticated API request
buckets = list(storage_client.list_buckets())
print(buckets)
我尝试运行的代码如下:
import io
import os
# Imports the Google Cloud client library
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
# Instantiates a client
client = speech.SpeechClient()
# The name of the audio file to transcribe
file_name = os.path.join(
os.path.dirname(__file__),
'resources',
'audio.raw')
# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file:
content = audio_file.read()
audio = types.RecognitionAudio(content=content)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code='en-US')
# Detects speech in the audio file
response = client.recognize(config, audio)
for result in response.results:
print('Transcript: {}'.format(result.alternatives[0].transcript))
我读过关于设置和验证环境变量的其他答案,但没有解决方案奏效。你知道吗
我还可以在anacondashell提示符的env文件夹中看到环境。有人知道为什么脚本找不到文件吗?你知道吗
错误消息是:
line 317, 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.
目前没有回答
相关问题 更多 >
编程相关推荐