Class: core/LexFeature

core/LexFeature(lexRuntime, optionsopt)

Feature class for interacting with Lex bot which the response from lex bot can be used for speech or other purpose.

Constructor

new core/LexFeature(lexRuntime, optionsopt)

Parameters:
Name Type Attributes Description
lexRuntime external:LexRuntime

The LexRuntime service that is used
to interact with lex bot. Will be undefined until initializeService
has been successfully executed

options Object <optional>

Options that will be used to interact with lex bot.

Properties
Name Type Attributes Description
botName string <optional>

The name of the lex bot.

botAlias string <optional>

The alias of the lex bot.

userId string <optional>

The userId used to keep track of the session with lex bot.

Properties:
Name Type Description
LEX_DEFAULTS Object

Default values to use with calls to external:LexRuntime.

Properties
Name Type Attributes Default Description
SampleRate string <optional>
'16000'
EVENTS Object

Built-in messages that the feature emits.

Properties
Name Type Attributes Default Description
lexResponseReady string <optional>
lexResponseReady

Message that is emitted after
receiving lex response for the input sent

micReady string <optional>
micReady

Message that is emitted after
microphone is ready to use

recordBegin string <optional>
recordBegin

Message that is emitted after
microphone starts recording

recordEnd string <optional>
recordEnd

Message that is emitted after
microphone ends recording

Extends

Members

(readonly) id :string

Gets the string id of the object.

Type:
  • string
Overrides:

Methods

_processWithAudio(inputAudio, sourceSampleRate, configopt) → {Promise}

Sends audio input to Amazon Lex.

Parameters:
Name Type Attributes Description
inputAudio TypedArray

TypedArray view of the input audio buffer

sourceSampleRate Number

Sample rate of the input audio

config Object <optional>

Optional config for overriding lex bot info

Properties
Name Type Attributes Description
botName string <optional>

The name of the lex bot.

botAlias string <optional>

The alias of the lex bot.

userId string <optional>

The userId used to keep track of the session with lex bot.

Returns:

A Promise-like object that resolves to a Lex response object.
For details on the structure of that response object see: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexRuntime.html#postContent-property

Type
Promise

_setupAudioContext()

Setup audio context which will be used for setting up microphone related audio node

beginVoiceRecording()

Begin microphone recording. This function will also try to resume audioContext so that
it's suggested to call this function after a user interaction

emit(message, valueopt)

Send a message, causing listener functions for the message on this object
to be executed.

Parameters:
Name Type Attributes Description
message string

The message to emit.

value any <optional>

Optional argument to pass to listener callbacks.

Overrides:

(async) enableMicInput()

Async function to setup microphone recorder which will get user permission for accessing microphone
This method must be called before attempting to record voice input with the
beginVoiceRecording() method. Expect an error to be thrown if the user has
chosen to block microphone access.

Throws:

See the documentation for
MediaDevices.getUserMedia().
The most likely error to expect will be the "NotAllowed" error indicating
the user has denied access to the microphone.

Type
DOMException

endVoiceRecording() → {Promise}

Stop microphone recording and send recorded audio data to lex.

Returns:

A Promise-like object that resolves to a Lex response object.
For details on the structure of that response object see: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexRuntime.html#postContent-property

Type
Promise

getEngineUserAgentString()

Returns:

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

listenTo(message, callback)

Execute a function when a message is received for this object.

Parameters:
Name Type Description
message string

The message to listen for.

callback function

Function to execute once the message is received.

Overrides:

processWithText(inputText, configopt) → {Promise}

Sends text user input to Amazon Lex.

Parameters:
Name Type Attributes Description
inputText String

Text to send to lex bot

config Object <optional>

Optional config for overriding lex bot info

Properties
Name Type Attributes Description
botName string <optional>

The name of the lex bot.

botAlias string <optional>

The alias of the lex bot.

userId string <optional>

The userId used to keep track of the session with lex bot.

Returns:

A Promise-like object that resolves to a Lex response object.
For details on the structure of that response object see: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/LexRuntime.html#postContent-property

Type
Promise

stopListening(message, callbackopt)

Prevent a function from being executed when a message is received for this
object.

Parameters:
Name Type Attributes Description
message string

The 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)

De-register callback(s) from being executed when messages matching the given
regular expression are received.

Parameters:
Name Type Attributes Description
regexp Regexp

regexp - The regular expression to filter messages with.

callback function <optional>

Optional callback to remove. If none is defined,
remove all callbacks for messages matching the regular expression.

Overrides:

stopListeningToAll()

Prevent any functions from being executed when any message is received for
this object.

Overrides: