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

浏览器兼容性