語音合成標記語言 (SSML)

您可以在傳送的 Text-to-Speech 要求中使用語音合成標記語言 (SSML),設定語音停頓,以及首字母縮略字、日期、時間、縮寫的讀法,或是指定須消音的文字等細節,讓音訊回應具備更高的自訂彈性。如需詳細資訊和程式碼範例,請參閱 Text-to-Speech 的 SSML 教學課程。

以下是 SSML 標記以及 Text-to-Speech 合成文字的範例:

<speak>
  Here are <say-as interpret-as="characters">SSML</say-as> samples.
  I can pause <break time="3s"/>.
  I can play a sound
  <audio src="https://www.example.com/MY_MP3_FILE.mp3">didn't get your MP3 audio file</audio>.
  I can speak in cardinals. Your number is <say-as interpret-as="cardinal">10</say-as>.
  Or I can speak in ordinals. You are <say-as interpret-as="ordinal">10</say-as> in line.
  Or I can even speak in digits. The digits for ten are <say-as interpret-as="characters">10</say-as>.
  I can also substitute phrases, like the <sub alias="World Wide Web Consortium">W3C</sub>.
  Finally, I can speak a paragraph with two sentences.
  <p><s>This is sentence one.</s><s>This is sentence two.</s></p>
</speak>

以下是含有合成文字的 SSML 範例文件:

Here are S S M L samples. I can pause [3 second pause]. I can play a sound [audio file plays].
I can speak in cardinals. Your number is ten.
Or I can speak in ordinals. You are tenth in line.
Or I can even speak in digits. The digits for ten are one oh.
I can also substitute phrases, like the World Wide Web Consortium.
Finally, I can speak a paragraph with two sentences. This is sentence one. This is sentence two.

Text-to-Speech 支援一部分可用的 SSML 標記,本主題將逐一說明這些標記。

如要進一步瞭解如何使用 Text-to-Speech,根據 SSML 輸入內容來建立音訊資料,請參閱「建立語音的音訊檔案」。

SSML 使用訣竅

根據您的實作情況,將 SSML 酬載傳送到 Text-to-Speech 時,可能會需要在 SSML 酬載中逸出引號。以下範例顯示如何設定 JSON 物件內 SSML 輸入內容的格式。

"{
    'input':{
     '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>'
    },
    'voice':{
      'languageCode':'en-us',
      'name':'en-US-Standard-B',
      'ssmlGender':'MALE'
    },
    'audioConfig':{
      'audioEncoding':'MP3'
    }
  }"

保留字元

請避免在要轉換為音訊的文字中使用 SSML 保留字元。如需使用這類保留字元,請使用逸出碼,避免系統將字元讀取為程式碼。下表列出保留的 SSML 字元及相關逸出碼。

字元 逸出碼
" &quot;
& &amp;
' &apos;
< &lt;
> &gt;

選取語音

您可以在 VoiceSelectionParams 物件中設定語音。請參閱 Text-to-Speech SSML 教學課程,觀看程式碼範例,瞭解如何使用 VoiceSelectionParams 物件。

您可以使用 <voice> 標記來以多種語音朗讀 SSML,但須將 VoiceSelectionParams 名稱設為相容的語音:

要求的語音類型 <voice> 標記支援的語音類型
Neural2 Studio Wavenet News Standard
Neural2 ✔ ✔ ✔
Studio ✔ ✔ ✔
Wavenet ✔ ✔ ✔