前提・実現したいこと
pythonでGCPのCloud speech to textを作成しています。
pytohnで実行すると以下のエラーメッセージが発生しました。
発生している問題・エラーメッセージ
エラーメッセージ
Traceback (most recent call last):
File ""path"/onsei.py", line 10, in <module>
client = speech.SpeechClient()
File ""path"\venv\lib\site-packages\google\cloud\speech_v1\gapic\speech_client.py", line 144, in init
address=self.SERVICE_ADDRESS, channel=channel, credentials=credentials
File "path"\venv\lib\site-packages\google\cloud\speech_v1\gapic\transports\speech_grpc_transport.py", line 61, in init
channel = self.create_channel(address=address, credentials=credentials)
File ""path"\test\venv\lib\site-packages\google\cloud\speech_v1\gapic\transports\speech_grpc_transport.py", line 92, in create_channel
address, credentials=credentials, scopes=cls._OAUTH_SCOPES
File ""path"venv\lib\site-packages\google\api_core\grpc_helpers.py", line 177, in create_channel
credentials, _ = google.auth.default(scopes=scopes)
File ""path"\venv\lib\site-packages\google\auth_default.py", 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. For more information, please see https://cloud.google.com/docs/authentication/getting-started
該当のソースコード
python
1import io 2import os 3 4# Imports the Google Cloud client library 5from google.cloud import speech 6from google.cloud.speech import enums 7from google.cloud.speech import types 8 9# Instantiates a client 10client = speech.SpeechClient() 11 12# The name of the audio file to transcribe 13file_name = "tensai.m4a" 14 15# Loads the audio into memory 16with io.open(file_name, 'rb') as audio_file: 17 content = audio_file.read() 18 audio = types.RecognitionAudio(content=content) 19 20config = types.RecognitionConfig(encoding=enums.RecognitionConfig.AudioEncoding.LINEAR16,sample_rate_hertz=16000,language_code='en-US') 21 22# Detects speech in the audio file 23response = client.recognize(config, audio) 24 25for result in response.results: 26 print('Transcript: {}'.format(result.alternatives[0].transcript))
試したこと
チュートリアルに沿って、set GOOGLE_APPLICATION_CREDENTIALSのjasonファイルも読み込ませて、実施しましたが、エラーが解消できませんでした。
補足情報(FW/ツールのバージョンなど)
pycharmをつかってpython3.7.3