Skip to content

Voicing

This page is the class-level API reference for the Voicing trait (from scenerystack/scenery) — its options, Properties, and methods as defined in source. For what Voicing is, why it's layered on top of the PDOM rather than replacing it, and worked examples, read the narrative guide at Voicing first; this page assumes that context and only documents the surface itself.

Voicing is a mixin function: Voicing( Node ) (or Voicing( SomeNodeSubclass )) returns a class with the response Properties and speak methods below, layered on top of InteractiveHighlighting (so every Voicing Node is also automatically interactive-highlighting-capable).

ts
import { Node, Voicing } from 'scenerystack/scenery';

class LaunchButtonNode extends Voicing( Node ) {
  public constructor() {
    super( {
      tagName: 'button',
      accessibleName: 'Launch',
      voicingNameResponse: 'Launch',
      voicingHintResponse: 'Launches the ball at the current angle and speed.'
    } );
  }
}

Options / response Properties

These are Voicing's mutator keys (VOICING_OPTION_KEYS in source):

OptionEffect
voicingNameResponseThe "what is it" response — a VoicingResponse (string, null, or a function/Property resolving to one)
voicingObjectResponseThe "current state" response
voicingContextResponseThe "what changed elsewhere" response
voicingHintResponseThe "how to interact" response
voicingResponsePatternCollectionA ResponsePatternCollection controlling how the four responses above are combined into spoken sentences
voicingIgnoreVoicingManagerPropertiesIf true, this Node's speech ignores the global response-category preferences (responseCollector) that normally let users silence hints, etc.
voicingUtteranceA specific Utterance instance to funnel all of this Node's speech through, instead of an internally-created one
voicingFocusListenerThe listener invoked on DOM focus; defaults to speaking the full response. Pass null to suppress automatic speech-on-focus
voicingPressableIf true, attaches a VoicingActivationResponseListener so responses are also spoken on press, not just focus

Each option has a matching getter/setter pair (setVoicingNameResponse() / voicingNameResponse, etc.), consistent with the rest of scenery's mutator pattern.

Speak-on-demand methods

MethodSpeaks
voicingSpeakFullResponse( options? )All four response categories currently assigned to the Node
voicingSpeakResponse( options? )Only whatever response strings are passed in options
voicingSpeakNameResponse( options? )The name response
voicingSpeakObjectResponse( options? )The object response
voicingSpeakContextResponse( options? )The context response
voicingSpeakHintResponse( options? )The hint response

SpeakingOptions accepts an utterance override alongside the response text, for one-off calls that shouldn't use voicingUtterance.

Voicing composes InteractiveHighlighting automatically

VoicingOptions extends InteractiveHighlightingOptions, and the trait's implementation class extends InteractiveHighlighting( Type ) internally — so a Voicing-enabled Node is already pointer-highlightable without separately mixing in InteractiveHighlighting. Mixing both traits directly on the same class is redundant and unnecessary.