1
3

More than 3 years have passed since last update.

AndroidからGoogle Cloud TTS を使ってみる 【SSML】

Posted at

概要

AndoirdからGoogle Cloud Text To Speech を使ってみる【音声を合成する】
の続きになります。

上記の記事では、Google Cloud Text To Speechを用いてAndroidアプリから音声合成を行う方法について紹介しました。

今回は、読み上げる音声がより自然な発話になるよう、SSMLを用いて発話をさせる方法についてメモしています。
SSMLについては下記をご参照ください。
音声合成マークアップ言語

実装方法

前回同様、下記のREST APIを利用していきます。
https://cloud.google.com/text-to-speech/docs/apis?hl=ja
(エンドポイント)
/v1beta1/text:synthesize

前回は文字列をそのまま投げていましたが、今回はSSMLをリクエストとして送信します。

(原文)

The SSML standard is defined by the W3C.

(SSML)

<speak>The <say-as interpret-as="characters">SSML</say-as>
          standard <break time="1s"/>is defined by the
          <sub alias="World Wide Web Consortium">W3C</sub>.</speak>

SSMLの文法については下記を参照
https://cloud.google.com/text-to-speech/docs/ssml?hl=ja

{
  "input": {
    object (SynthesisInput)
  },
  "voice": {
    object (VoiceSelectionParams)
  },
  "audioConfig": {
    object (AudioConfig)
  }
}

今回は上記のリクエストボディのSynthesisInputにSSML文字列を入れていきます。


    data class SynthesisInput(
        val ssml: String
    )

SSMLサンプル ("をエスケープ)

<speak>The <say-as interpret-as=\\\"characters\\\">SSML</say-as>" +
            "standard <break time=\\\"1s\\\"/>is defined by the " +
            "<sub alias=\\\"World Wide Web Consortium\\\">W3C</sub>.</speak>

前回のサンプルを上記のSSMLを用いた実装に書き換えるとより自然な音声読み上げを試すことができます。

今回のサンプルの全てのコードはこちらのGithubリポジトリをご参照ください
https://github.com/k-masashi/GoogleCloudTtsAndroidSample/tree/ssml

1
3
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
1
3