LoginSignup
0
0

[Google Cloud Text-to-Speech API(V1)] Javaで音声の変換がサポートされている音声リストを取得する

Posted at

Cloud Text-to-Speech API V1(Java)を使用して、
Javaで音声の変換がサポートされている音声リストを取得する方法
についてご紹介します。

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

No 目次
1 サポートリストを取得
1 スコープ
2 実行
3 レスポンスの内容

1. サポートリストを取得

音声の変換がサポートされている音声リストを取得します。

1.1. スコープ

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

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

1.2. 実行

public static void main(String[] args) throws Exception{
    try(TextToSpeechClient client = getTextToSpeechClient()){
        ListVoicesRequest.Builder builder = ListVoicesRequest.newBuilder();
        builder.setLanguageCode("ja");
        
        ListVoicesResponse response = client.listVoices(builder.build());
        System.out.println(response);
    }
}

1.2.1. HTTPリクエスト

GET: https://texttospeech.googleapis.com/v1/voices
が実行されます。

1.2.2. クエリパラメータ

ListVoicesRequest.Builderのsetメソッドにより、リクエストボディを追加できます。
build()メソッドでListVoicesRequestインスタンスを取得し、
listVoices()に渡します。

メソッド 引数 説明
setLanguageCode String 取得する言語(省略時は全ての言語を取得)

1.3. レスポンスの内容

Voice

メソッド 戻り値 説明
getLanguageCodes(0) String サポートする言語
getName String 声の名前
getSsmlGender SsmlVoiceGender(enum) 声の性別
getNaturalSampleRateHertz int 音声のサンプルレート(ヘルツ)

SsmlVoiceGender

定義値 内容
SSML_VOICE_GENDER_UNSPECIFIED 性別不詳
MALE 男性の声
FEMALE 女性の声
NEUTRAL 性別を問わない声(未サポート)


おしまい。。
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