SpeechSynthesisEvent
Web Speech API 的 SpeechSynthesisEvent 接口包含有关语音服务中已处理的 SpeechSynthesisUtterance 对象当前状态的信息。
构造函数
SpeechSynthesisEvent()-
创建一个新的
SpeechSynthesisEvent。
实例属性
SpeechSynthesisEvent 接口还继承了其父接口 Event 的属性。
SpeechSynthesisEvent.charIndex只读-
返回事件触发时,在
SpeechSynthesisUtterance.text中正在朗读的字符的索引位置。 SpeechSynthesisEvent.charLength只读-
如果语音引擎支持,则返回
charIndex位置之后剩余要朗读的字符数。如果语音引擎无法提供此信息,则返回 0。 SpeechSynthesisEvent.elapsedTime只读-
返回事件触发时,在
SpeechSynthesisUtterance.text开始朗读后经过的秒数。 SpeechSynthesisEvent.name只读-
返回与
SpeechSynthesisUtterance.text正在朗读时发生的某些类型事件相关的名称:对于mark事件,是遇到的 SSML 标记的名称;对于boundary事件,是遇到的边界的类型。 SpeechSynthesisEvent.utterance只读-
返回触发事件的
SpeechSynthesisUtterance实例。
实例方法
SpeechSynthesisEvent 接口还继承了其父接口 Event 的方法。
示例
js
utterThis.onpause = (event) => {
const char = event.utterance.text.charAt(event.charIndex);
console.log(
`Speech paused at character ${event.charIndex} of "${event.utterance.text}", which is "${char}".`,
);
};
utterThis.onboundary = (event) => {
console.log(
`${event.name} boundary reached after ${event.elapsedTime} seconds.`,
);
};
规范
| 规范 |
|---|
| Web Speech API # speechsynthesisevent |
浏览器兼容性
加载中…