質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.50%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Q&A

1回答

2658閲覧

Cloud speech to text API

takeo_0811

総合スコア13

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

0グッド

1クリップ

投稿2019/06/12 09:53

前提・実現したいこと

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

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

kazto

2019/06/12 11:50

Pythonを実行している環境は、Windowsでしょうか?
takeo_0811

2019/06/16 13:05

はい、windowsです。遅くなり申し訳ありません。
guest

回答1

0

チュートリアルに沿って、set GOOGLE_APPLICATION_CREDENTIALSのjasonファイルも読み込ませて、実施しましたが、エラーが解消できませんでした。

ひとつ確認させてください。
上記は、環境変数にjsonファイルへのパスを設定する、ということですが、認識はあっていますでしょうか。

投稿2019/06/17 03:45

kazto

総合スコア7196

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

takeo_0811

2019/06/17 03:46

はい。おっしゃる通りです。
kazto

2019/06/17 05:06

一方で、それでもなお「google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application.」とエラーが出るのであれば、指定したパスの内容が合っていない、環境変数を設定したあとログアウトして有効にしていない、など考えられます。
takeo_0811

2019/06/20 02:56

ありがとうございます。再度試してみます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.50%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問