Connection class
Connection is a proxy class for managing connection to the speech service of the specified Recognizer. By default, a Recognizer autonomously manages connection to service when needed. The Connection class provides additional methods for users to explicitly open or close a connection and to subscribe to connection status changes. The use of Connection is optional, and mainly for scenarios where fine tuning of application behavior based on connection status is needed. Users can optionally call Open() to manually set up a connection in advance before starting recognition on the Recognizer associated with this Connection. If the Recognizer needs to connect or disconnect to service, it will setup or shutdown the connection independently. In this case the Connection will be notified by change of connection status via Connected/Disconnected events. Added in version 1.2.1.
Properties
connected | The Connected event to indicate that the recognizer is connected to service. |
disconnected | The Disconnected event to indicate that the recognizer is disconnected from service. |
message |
Any message received from the Speech Service. |
message |
Any message sent to the Speech Service. |
received |
Any message from service that is not being processed by any other top level recognizers. Will be removed in 2.0. |
Methods
close() | Dispose of associated resources. |
close |
Closes the connection the service. Users can optionally call closeConnection() to manually shutdown the connection of the associated Recognizer. If closeConnection() is called during recognition, recognition will fail and cancel with an error. |
from |
Gets the Connection instance from the specified recognizer. |
from |
Gets the Connection instance from the specified synthesizer. |
open |
Starts to set up connection to the service. Users can optionally call openConnection() to manually set up a connection in advance before starting recognition on the Recognizer associated with this Connection. After starting recognition, calling Open() will have no effect Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to be notified when the connection is established. |
send |
Sends a message to the speech service. Added in version 1.13.0. |
set |
Appends a parameter in a message to service. Added in version 1.12.1. |
Property Details
connected
The Connected event to indicate that the recognizer is connected to service.
connected: (args: ConnectionEventArgs) => void
Property Value
(args: ConnectionEventArgs) => void
disconnected
The Disconnected event to indicate that the recognizer is disconnected from service.
disconnected: (args: ConnectionEventArgs) => void
Property Value
(args: ConnectionEventArgs) => void
messageReceived
Any message received from the Speech Service.
messageReceived: (args: ConnectionMessageEventArgs) => void
Property Value
(args: ConnectionMessageEventArgs) => void
messageSent
Any message sent to the Speech Service.
messageSent: (args: ConnectionMessageEventArgs) => void
Property Value
(args: ConnectionMessageEventArgs) => void
receivedServiceMessage
Any message from service that is not being processed by any other top level recognizers.
Will be removed in 2.0.
receivedServiceMessage: (args: ServiceEventArgs) => void
Property Value
(args: ServiceEventArgs) => void
Method Details
close()
Dispose of associated resources.
function close()
closeConnection(() => void, (error: string) => void)
Closes the connection the service. Users can optionally call closeConnection() to manually shutdown the connection of the associated Recognizer.
If closeConnection() is called during recognition, recognition will fail and cancel with an error.
function closeConnection(cb?: () => void, err?: (error: string) => void)
Parameters
- cb
-
() => void
- err
-
(error: string) => void
fromRecognizer(Recognizer | ConversationTranscriber)
Gets the Connection instance from the specified recognizer.
static function fromRecognizer(recognizer: Recognizer | ConversationTranscriber): Connection
Parameters
- recognizer
The recognizer associated with the connection.
Returns
The Connection instance of the recognizer.
fromSynthesizer(SpeechSynthesizer)
Gets the Connection instance from the specified synthesizer.
static function fromSynthesizer(synthesizer: SpeechSynthesizer): Connection
Parameters
- synthesizer
- SpeechSynthesizer
The synthesizer associated with the connection.
Returns
The Connection instance of the synthesizer.
openConnection(() => void, (error: string) => void)
Starts to set up connection to the service. Users can optionally call openConnection() to manually set up a connection in advance before starting recognition on the Recognizer associated with this Connection. After starting recognition, calling Open() will have no effect
Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to be notified when the connection is established.
function openConnection(cb?: () => void, err?: (error: string) => void)
Parameters
- cb
-
() => void
- err
-
(error: string) => void
sendMessageAsync(string, string | ArrayBuffer, () => void, (error: string) => void)
Sends a message to the speech service. Added in version 1.13.0.
function sendMessageAsync(path: string, payload: string | ArrayBuffer, success?: () => void, error?: (error: string) => void)
Parameters
- path
-
string
The WebSocket path of the message
- payload
-
string | ArrayBuffer
The payload of the message. This is a json string or a ArrayBuffer.
- success
-
() => void
A callback to indicate success.
- error
-
(error: string) => void
A callback to indicate an error.
setMessageProperty(string, string, string | object)
Appends a parameter in a message to service. Added in version 1.12.1.
function setMessageProperty(path: string, propertyName: string, propertyValue: string | object)
Parameters
- path
-
string
The path of the network message.
- propertyName
-
string
Name of the property
- propertyValue
-
string | object
Value of the property. This is a json string.