LoginSignup
0
0

[Google Cloud Speech-to-Text API(V2)] Javaでコンフィグレーションを取得する

Posted at

Cloud Speech-to-Text API V2(Java)を使用して、
Speech-to-Textのコンフィグレーションを取得する方法についてご紹介します。

APIを利用する環境の準備から始める場合や、コードを実行する際は、
⧉[Google Cloud Speech-to-Text API(V2)] JavaでSpeech-to-Text APIを使ってみる
を参照ください。

No 目次
1 コンフィグを取得
1 スコープ
2 実行
3 レスポンスの内容

1. コンフィグを取得

Speech-to-Textのコンフィグレーションを取得します。

1.1. スコープ

OAuth2.0でこのAPIを実行するには、以下のスコープを指定してください。
サービスアカウントで実行する場合はスコープの指定は不要です。

https://www.googleapis.com/auth/cloud-platform

1.2. 実行

public static void main(String[] args) throws Exception{
    try(SpeechClient client = getSpeechClient()){
        GetConfigRequest.Builder builder = GetConfigRequest.newBuilder();
        builder.setName(String.format(
                    "projects/%s/locations/%s/config", 
                    "プロジェクトID","ロケーションID"));
        
        Config response = client.getConfig(builder.build());
        System.out.println(response);
    }
}

1.2.1. HTTPリクエスト

GET: https://speech.googleapis.com/v2/projects/{プロジェクトID}/locations/{ロケーションID}/config
が実行されます。

1.2.2. クエリパラメータ

GetConfigRequest.Builderのsetメソッドにより、クエリパラメータを追加できます。
build()メソッドでGetConfigRequestインスタンスを取得し、
getConfig()に渡します。

メソッド 引数 説明
setName String 【必須】リソース名
形式:"projects/{プロジェクトID}/locations/{ロケーションID}/config"

1.3. レスポンスの内容

Config

メソッド 戻り値 説明
getName String 構成リソースの名前
形式:"projects/{プロジェクトID}/locations/{ロケーションID}/config"
getKmsKeyName String オプションのKMSキー名
形式:"projects/{プロジェクトID}/locations/{ロケーションID}/keyRings/{key_ring}/cryptoKeys/{crypto_key}
getUpdateTime Timestamp このリソースが最後に変更された時刻


おしまい。。
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0