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 语音 API # dom-speechsynthesisevent-charlength |
浏览器兼容性
BCD 表格仅在浏览器中加载