GCPのSpeech-To-Textを試そうと思ったが、スタート地点にも立てなかった話
Googleの音声認識サービス「Speech-To-Text」(以降sttと記載)。
自分の声を認識させて、出力された文字をVOICEROIDに入力して喋らすってことをしたかったのだが、公式サイトのサンプルが動かない。
Pythonで書いていたが、実行すると以下のようなエラーが出る。
(env) C:\Users\rnorp\Desktop\stt>python quickstart.py
Traceback (most recent call last):
File "quickstart.py", line 5, in <module>
client = speech.SpeechClient()
File "C:\Users\rnorp\Desktop\stt\env\lib\site-packages\google\cloud\speech_v1\services\speech\client.py", line 375, in __init__
always_use_jwt_access=True,
File "C:\Users\rnorp\Desktop\stt\env\lib\site-packages\google\cloud\speech_v1\services\speech\transports\grpc.py", line 158, in __init__
always_use_jwt_access=always_use_jwt_access,
File "C:\Users\rnorp\Desktop\stt\env\lib\site-packages\google\cloud\speech_v1\services\speech\transports\base.py", line 106, in __init__
**scopes_kwargs, quota_project_id=quota_project_id
File "C:\Users\rnorp\Desktop\stt\env\lib\site-packages\google\auth\_default.py", line 464, in default
credentials, project_id = checker()
File "C:\Users\rnorp\Desktop\stt\env\lib\site-packages\google\auth\_default.py", line 457, in <lambda>
lambda: _get_explicit_environ_credentials(quota_project_id=quota_project_id),
File "C:\Users\rnorp\Desktop\stt\env\lib\site-packages\google\auth\_default.py", line 227, in _get_explicit_environ_credentials
os.environ[environment_vars.CREDENTIALS], quota_project_id=quota_project_id
File "C:\Users\rnorp\Desktop\stt\env\lib\site-packages\google\auth\_default.py", line 111, in load_credentials_from_file
"File {} was not found.".format(filename)
google.auth.exceptions.DefaultCredentialsError: File "C:\velvety-folder-338712-d922ab0834b2.json" was not found.
(env) C:\Users\rnorp\Desktop\stt>
credencialsのエラーが出てる…?
チュートリアル通りにしてるはずなのに…
Pythonは3.6.8をインストール。
portaudioってのが3.7以降使われへんらしいから。
GCP上でstt用のプロジェクトを作ったし、秘密鍵も作って保存した。
set GOOGLE_APPLICATION_CREDENTIALS="C:\credentials.json"
クライアントライブラリもインストールした。
pip install --upgrade google-cloud-speech
何が間違っているのか。
原因
環境変数でした。
credentialsのエラーが出てるからそらそうか。
パスを囲ってるダブルコーテーションがいらんかった…。
正しくは
set GOOGLE_APPLICATION_CREDENTIALS=C:\credentials.json
これのせいで何時間無駄にしたか…。
気づいた原因は、.pyに以下を書いたら動いたから。
import os
os.environ['GOOGLE_APPLICATION_CREDENTIALS'] = 'credentials.json'
pythonで環境変数を設定して動くってことは、同じく環境変数を設定するsetコマンドが間違ってるってことになるよね。
早くstt使って茜ちゃんに喋らせたいのに…。😡