Skip to main content

Get Player State

One common use-case for publishers is the fetch the current state of the player and the listening experience. We make this simple using one function: getPlayerState().


).then(async (speechifyWidget) => {
const widget = speechifyWidget.makeSpeechifyExperience(config);
await widget.mount({
rootElement: document.getElementById("article"),
useSpeechifyRoot: true,
console.log(widget.getState().progressFraction); // 0.0
console.log(widget.getState().speedWPM); // 220

Player State Object

The player state object is returned by the getPlayerState() and included in event listener callbacks as well. Here are the properties of the object:

  • progressFraction: number a value between 0 and 1 representing the current position of the content, where 0 is the start and 1 is the end of the content.
  • playing: boolean whether content is currently being played
  • audioLengthSeconds: number the length of the article in seconds. This value will not always be exact since we lazy-load audio, although it is generally closely accurate.
  • loading: boolean whether audio is currently being loaded and the audio is buffering.
  • voiceId: string current voice ID.
  • voiceDisplayName: string current voice display name.
  • speedWPM: number current speed in WPM.
  • speedMultiplier: number current speed multiplier. Ex: 2.0 where the audio is in 2x speed.
  • inlinePlayerShown: boolean whether the inline player is shown.
  • widgetShown: boolean whether the widget is shown.
  • widgetMaximized: boolean whether the widget is maximized.
  • voiceDrawerShown: boolean whether the voice drawer is shown.
  • speedDrawerShown: boolean whether the speed drawer is shown.