SpeechSynthesisEvent: charLength 属性
charLength 是 SpeechSynthesisEvent 接口的一个只读属性,它返回在 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 |
浏览器兼容性
加载中…