HSSpeaker
TypeA 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
voice
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
The speaking rate, from 0.0 (slowest) to 1.0 (fastest). Defaults to 0.5, the normal rate.
prefersAssistiveTechnologySettings
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.
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. |
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 voiceconst 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
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. |
s.pause()
resume() -> HSSpeaker
Continues speech paused by pause().
resume() -> HSSpeaker
s.resume()