Я пытаюсь использовать облачную платформу Google (GCP) для API преобразования речи в текст в python, но по какой-то причине я не могу получить доступ к GCP для использования API. Как аутентифицировать мои учетные данные?
Я пытался следовать инструкциям, предоставленным Google, чтобы подтвердить свои учетные данные, но я просто потерян, потому что, похоже, ничего не работает.
Я создал проект GCP, настроил информацию для выставления счетов, включил API и создал учетную запись службы без каких-либо проблем.
Я попытался установить свою среду с помощью командной строки на set GOOGLE_APPLICATION_CREDENTIALS=[PATH]
и затем запустите следующий код, который был взят прямо со страницы учебника Google:
def transcribe_streaming(stream_file):
"""Streams transcription of the given audio file."""
from google.cloud import speech
from google.cloud.speech import enums
from google.cloud.speech import types
client = speech.SpeechClient()
with io.open(stream_file, 'rb') as audio_file:
content = audio_file.read()
# In practice, stream should be a generator yielding chunks of audio data.
stream = [content]
requests = (types.StreamingRecognizeRequest(audio_content=chunk)
for chunk in stream)
config = types.RecognitionConfig(
encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,
sample_rate_hertz=16000,
language_code='en-US')
streaming_config = types.StreamingRecognitionConfig(config=config)
# streaming_recognize returns a generator.
responses = client.streaming_recognize(streaming_config, requests)
for response in responses:
# Once the transcription has settled, the first result will contain the
# is_final result. The other results will be for subsequent portions of
# the audio.
for result in response.results:
print('Finished: {}'.format(result.is_final))
print('Stability: {}'.format(result.stability))
alternatives = result.alternatives
# The alternatives are ordered from most likely to least.
for alternative in alternatives:
print('Confidence: {}'.format(alternative.confidence))
print(u'Transcript: {}'.format(alternative.transcript))
Я получаю следующее сообщение об ошибке:
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://cloud.google.com/docs/authentication/getting-started