SpeechSynthesisEvent: charLength 屬性

Baseline 已廣泛支援

此功能已成熟,並可在多種裝置和瀏覽器版本上執行。自 2022 年 9 月起,所有瀏覽器都已支援此功能。

charLengthSpeechSynthesisEvent 介面的一個只讀屬性,它返回在 charIndex 位置的字元之後剩餘的待朗讀字元數。

如果語音引擎無法確定,則返回 0。

一個整數。

示例

js
utterThis.onpause = (event) => {
  const char = event.utterance.text.charAt(event.charIndex);
  const charLeft = event.charLength;
  if (charLeft) {
    console.log(
      `Speech paused. There are still ${charLeft} characters to be spoken.`,
    );
  } else {
    console.log(
      "Speech paused. The underlying speech engine can't tell how many characters are left.",
    );
  }
};

規範

規範
Web Speech API
# dom-speechsynthesisevent-charlength

瀏覽器相容性