API Docs

A text-to-speech speaker, with its own queue of speech. Create one with hs.speech.create().

Text passed to speak() is queued, and spoken after anything already queued. The voice, rate, pitch, volume and prefersAssistiveTechnologySettings properties apply to speech queued after they are set, and can be overridden for a single utterance with speak()'s options.

Properties

identifier

string

A unique identifier for this speaker.

voice

string | null

The identifier of the voice this speaker uses, or null for the system's default voice. Assign a voice's identifier or name (see hs.speech.voices()) to change it, or null to go back to the default. An unknown voice is ignored, and logged.

rate

number

The speaking rate, from 0.0 (slowest) to 1.0 (fastest). Defaults to 0.5, the normal rate.

pitch

number

The pitch multiplier, from 0.5 to 2.0. Defaults to 1.0.

volume

number

The volume, from 0.0 (silent) to 1.0 (full volume). Defaults to 1.0.

prefersAssistiveTechnologySettings

boolean

Whether to speak with the settings of a running assistive technology, such as VoiceOver's voice and rate, instead of this speaker's voice, rate, pitch and volume. Defaults to false. Has no effect when no assistive technology is running.

isSpeaking

boolean

Whether this speaker is speaking, paused or has speech queued.

isPaused

boolean

Whether this speaker has been paused with pause().

Methods

speak(text, options) -> Promise<boolean>

Queues text to be spoken. Speech queued by earlier calls is spoken first.

speak(text, options) -> Promise<boolean>
Name Type Description
text string The text to speak.
options optional HSSpeechOptions How to speak this text, overriding the speaker's properties.
Promise<boolean>
Resolves to true when the text has been spoken, or false if it was interrupted by stop(). Rejects if an option is invalid, such as an unknown voice
A speaker with speech queued keeps speaking even if you don't keep a reference to it
const s = hs.speech.create()
s.speak("First")
s.speak("Second, and louder", { volume: 1.0, pitch: 1.3 })
    .then(finished => console.log("Finished: " + finished))

stop() -> HSSpeaker

Stops speaking immediately, discarding any queued speech. The Promises of the interrupted utterances resolve to false.

stop() -> HSSpeaker
This speaker, for chaining.
s.stop().speak("Never mind that")

pause(atWordBoundary) -> HSSpeaker

Pauses speech, which can be continued with resume(). Queued speech stays queued.

pause(atWordBoundary) -> HSSpeaker
Name Type Description
atWordBoundary optional boolean If true, finishes the current word before pausing. Defaults to false, which pauses immediately.
This speaker, for chaining.
s.pause()

resume() -> HSSpeaker

Continues speech paused by pause().

resume() -> HSSpeaker
This speaker, for chaining.
s.resume()