Options
All
  • Public
  • Public/Protected
  • All
Menu

A TtsSynthesizer implementation using the Web Speech API for synthesizing text.

Hierarchy

  • WebSpeechTtsSynthesizer

Implements

Index

Constructors

constructor

  • A TtsSynthesizer implementation using the Web Speech API for synthesizing text.

    You can optionally provide a callback function that will be called when the synthesizer creates a new utterance, but before the utterance is sent to the speechSynthesis engine. This happens after all the properties on the utterance have been set to their default values. The callback allows you to modify the utterance, such as setting the voice or any other attribute you'd like to change.

    When changing the voice of an utterance, it is important to also change the language of the utterance. Otherwise, the voice attribute may be ignored in some browsers. Example:

    new WebSpeechTtsSynthesizer(utterance => {
    utterance.voice = myVoice;
    utterance.lang = myVoice.lang
    })

    Parameters

    • Optional onConfigureUtterance: (utterance: SpeechSynthesisUtterance, utteranceAdditionalData?: ITtsUtteranceData) => void
        • (utterance: SpeechSynthesisUtterance, utteranceAdditionalData?: ITtsUtteranceData): void
        • Parameters

          • utterance: SpeechSynthesisUtterance
          • Optional utteranceAdditionalData: ITtsUtteranceData

          Returns void

    Returns WebSpeechTtsSynthesizer

Methods

addUtterance

clearAndPause

  • clearAndPause(): void
  • The implementation must stop any current playing utterance and set itself in paused state. It should then clear the queue of utterances to speak.

    Returns void

destroy

  • destroy(): void
  • Destroys this instance. The synthesizer should clear the utterance queue and set itself in paused state. The reference to any context passed with init() is released.

    Returns void

handleEvent

  • handleEvent(evt: Event): void
  • Parameters

    • evt: Event

    Returns void

init

pause

  • pause(): void
  • Will be called by the SyncMediaPlayer when it should pause playback.

    Returns void

play

  • play(): void
  • Resume the playback of the current active utterance if any exists, otherwise the next utterance from the utterance queue. The implementation must use context.onUtteranceEnd() when each utterance has finished speaking.

    The implementation should also call context.onBoundary(charOffset) to indicate which part of the utterance is currently being spoken to allow the media player to get a more accurate timeline position for things like automatically turning pages and resuming playback and for highlighting.

    Returns void

setMuted

  • setMuted(muted: boolean): void
  • Sets if playback should be muted. When called with false, the synthesizer should unmute and use the playback volume last set by setVolume.

    Parameters

    • muted: boolean

    Returns void

setPlaybackRate

  • setPlaybackRate(playbackRate: number): void
  • Will be called by the SyncMediaPlayer when its playbackRate has been changed.

    Parameters

    • playbackRate: number

    Returns void

setVolume

  • setVolume(volume: number): void
  • Will be called by the SyncMediaPlayer when its volume has been changed.

    Parameters

    • volume: number

    Returns void

Generated using TypeDoc