Class: AbstractTextToSpeechFeature

(abstract) AbstractTextToSpeechFeature(host, optionsopt)

Base class for turning text input into playable audio. There should be one instance
per speaker, each instance can play only one piece of text at a time.

Constructor

(abstract) new AbstractTextToSpeechFeature(host, optionsopt)

Parameters:
Name Type Attributes Description
host core/HostObject

Host object managing the feature.

options Object <optional>

Options that will be sent to Polly for each speech.

Properties
Name Type Attributes Default Description
voice string <optional>

The name of the Polly voice to use for all speech.

engine string <optional>

The name of the Polly engine to use for all speech.

language string <optional>

The name of the language to use for all speech.

audioFormat audioFormat <optional>
'mp3'

The format to use for generated
audio for all speeches.

sampleRate string <optional>

The sample rate for audio files for all
speeches.

speechmarkOffset number <optional>
0

Amount of time in seconds to
offset speechmark event emission from the audio.

minEndMarkDuration number <optional>
.05

The minimum amount of time
in seconds that the last speechmark of each type in a speech can have its
duration property set to.

volume number <optional>
1

The default volume to play speech audio
with.

isGlobal boolean <optional>
false

Whether the audio source should default
to global regardless of whether or not it is attached to an object.

Properties:
Name Type Attributes Default Description
AWS_VERSION number | undefined

Gets the version of AWS SDK being
used. Will be undefined until initializeService
has been successfully executed.

POLLY_MIN_NEURAL_VERSION string <optional>
'2.503'

Gets the minimum version
of the AWS SDK that is necessary to use neural voices with AWS Polly.

POLLY_DEFAULTS Object

Default values to use with calls to external:Polly.

Properties
Name Type Attributes Default Description
Engine string <optional>
'standard'
LexiconNames Array.<string> <optional>
[]
OutputFormat string <optional>
'mp3'
SampleRate string <optional>
'22050'
Text string <optional>
''
TextType string <optional>
'ssml'
VoiceId string <optional>
'Amy'
LanguageCode string <optional>
'en-GB'
LanguageName string <optional>
'British English'
POLLY_VOICES Array.<string> <optional>
[]

An array of voices available in
Polly. Will be empty until initializeService
has been successfully executed. See Polly Documentation
for a full list of available voices.

POLLY_LANGUAGES Object <optional>
{}

An object that maps language names
to language codes that are available in Polly. Will be empty until
initializeService
has been successfully executed. See Polly Documentation
for a full list of available languages and corresponding codes.

POLLY_LANGUAGE_CODES Object <optional>
{}

An object that maps language codes
to language names that are available in Polly. Will be empty until
initializeService
has been successfully executed. See Polly Documentation
for a full list of available languages and corresponding codes.

EVENTS Object

Built-in messages that the feature emits. When the
feature is added to a core/HostObject, event names will be prefixed by the
name of the feature class + '.'.

Properties
Name Type Attributes Default Description
ready string <optional>
onReadyEvent

Message that is emitted after
initializeService has been
successfully executed.

play string <optional>
onPlayEvent

Message that is emitted after
each call to play. The speech that was played
is supplied as an argument to listener functions.

pause string <optional>
onPauseEvent

Message that is emitted after
each call to pause. The speech that was paused
is supplied as an argument to listener functions.

resume string <optional>
onResumeEvent

Message that is emitted after
each call to resume. The speech that was
resumed is supplied as an argument to listener functions.

interrupt string <optional>
onInterruptEvent

Message that is emitted
if there is a current speech in progress and play
or resume are executed for a new speech.
The speech that was interrupted is supplied as an argument to listener functions.

stop string <optional>
onStopEvent

Message that is emitted after
each call to stop and when a speech reaches
the end of playback. The speech that was stopped is supplied as an argument
to listener functions.

sentence string <optional>
onSentenceEvent

Message that is emitted
each time a sentence speechmark is encountered whose timestamp matches up with
the speech audio's current time. The sentence speechmark object is supplied as
an argument to listener functions.

word string <optional>
onWordEvent

Message that is emitted
each time a word speechmark is encountered whose timestamp matches up with
the speech audio's current time. The word speechmark object is supplied as
an argument to listener functions.

viseme string <optional>
onVisemeEvent

Message that is emitted
each time a viseme speechmark is encountered whose timestamp matches up with
the speech audio's current time. The viseme speechmark object is supplied as
an argument to listener functions.

ssml string <optional>
onSsmlEvent

Message that is emitted
each time a ssml speechmark is encountered whose timestamp matches up with
the speech audio's current time. The ssml speechmark object is supplied as
an argument to listener functions.

SERVICES Object

AWS services that are necessary for the feature
to function.

Properties
Name Type Description
polly external:Polly

The Polly service that is used
to synthesize speechmarks. Will be undefined until initializeService
has been successfully executed

presigner external:Presigner

The Polly Presigner
object that is used to synthesize speech audio. Will be undefined until
initializeService
has been successfully executed.

Extends

Members

(static, readonly) isReady :boolean

Indicates whether or not the class is capable of generating speech audio. Polly,
Presigner and AWS SDK version number must have been defined using
initializeService.

Type:
  • boolean

(readonly) currentSpeech :string

Gets the text of the currently playing speech.

Type:
  • string

(readonly) host

Gets the host that manages the feature.

Overrides:

minEndMarkDuration :number

Gets and sets the The minimum amount of time in seconds that the last
speechmark of each type in a speech can have its duration property set to.

Type:
  • number

(readonly) owner

Gets the engine owner object of the host.

Overrides:

speechmarkOffset :number

Gets and sets the number of seconds to offset speechmark emission.

Type:
  • number

volume :number

Gets and sets the volume used for all audio clips played by the speaker.

Type:
  • number

(readonly) volumePending :boolean

Gets whether or not the speaker's volume value is currently being tweened.

Type:
  • boolean

Methods

(static) initializeService(polly, presigner, version)

Store Polly, Presigner and AWS SDK Version for use across all instances.

Parameters:
Name Type Description
polly external:Polly

Polly instance to use to generate speechmarks.

presigner external:Presigner

Presigner instance to use to generate
audio URLs.

version string

Version of the AWS SDK to use to validate voice options.

discard()

Clean up once the feature is no longer in use. Remove the feature namespace
from the host and remove reference to the host.

Overrides:

emit(message, valueopt)

Emit feature messages from the host. Feature messages will be prefixed with
the class name of the feature.

Parameters:
Name Type Attributes Description
message string

The message to emit.

value any <optional>

Optional parameter to pass to listener callbacks.

Overrides:

getEngineUserAgentString()

Returns:

The useragent string for the engine you are using, e.g. 'babylonjs/5.1.0'

getVolume() → {number}

Gets the volume used for all audio clips played by the speaker.

Returns:
Type
number

installApi()

Adds a namespace to the host with the name of the feature to contain properties
and methods from the feature that users of the host need access to.

Overrides:
See:

listenTo(message, callback)

Listen to a feature message from the host object.

Parameters:
Name Type Description
message string

Message to listen for.

callback function

The callback to execute when the message is received.

Overrides:

pause()

If a speech is currently playing, pause it at the current time.

pauseVolume() → {boolean}

Pause interpolation happening on the speaker's volume property.

Returns:
Type
boolean

play(text, configopt) → {Deferred}

Stop any speeches currently playing and play a new speech from the beginning.

Parameters:
Name Type Attributes Description
text string

The text of the new speech to play.

config Object <optional>

Optional parameters for the speech.

Returns:
Type
Deferred

resume(textopt, configopt) → {Deferred}

Stop any speeches currently playing and resume a new speech from the current
time.

Parameters:
Name Type Attributes Description
text string <optional>

The text of the new speech to play. If undefined and
there is a current speech that is paused, the current speech will be resumed.

config Object <optional>

Optional parameters for the speech.

Returns:
Type
Deferred

resumeVolume() → {boolean}

Resume any interpolation happening on the speaker's volume property.

Returns:
Type
boolean

setVolume(volume, secondsopt, easingFnopt) → {Deferred}

Updates the volume used for all audio clips played by the speaker over time.

Parameters:
Name Type Attributes Default Description
volume number

Target volume value.

seconds number <optional>
0

Amount of time it will take to reach the target
volume.

easingFn function <optional>

Easing function used for interpolation.

Returns:
Type
Deferred

stop()

If a speech is currently playing, stop playback and reset time.

stopListening(message, callbackopt)

Stop listening to a message from the host object.

Parameters:
Name Type Attributes Description
message string

Message to stop listening for.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for the message.

Overrides:

stopListeningByRegexp(regexp, callbackopt)

Stop listening to a message matching the given regular expression from the
host object.

Parameters:
Name Type Attributes Description
regexp Regexp

The regular expression to stop listening for.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for the message.

Overrides:

stopListeningToAll()

Stop listening to all messages.

Overrides:

update(deltaTime)

Update the currently playing speech.

Parameters:
Name Type Description
deltaTime number

Time since the last update.

Overrides: