Back to Content

SpeechSynthesisEvent: charIndex property

files/en-us/web/api/speechsynthesisevent/charindex/index.md

latest680 B
Original Source

{{APIRef("Web Speech API")}}

The charIndex read-only property of the {{domxref("SpeechSynthesisUtterance")}} interface returns the index position of the character in {{domxref("SpeechSynthesisUtterance.text")}} that was being spoken when the event was triggered.

Value

A number.

Examples

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}".`,
  );
};

Specifications

{{Specifications}}

Browser compatibility

{{Compat}}

See also