Connection Class
Definition
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. It is intended for scenarios where fine tuning of application behavior based on connection status is needed. Users can optionally call openConnection() to manually initiate a service connection before starting recognition on the Recognizer associated with this Connection. After starting a recognition, calling openConnection() or closeConnection() might fail. This will not impact the Recognizer or the ongoing recognition. Connection might drop for various reasons, the Recognizer will always try to reinstitute the connection as required to guarantee ongoing operations. In all these cases Connected/Disconnected events will indicate the change of the connection status. Note: close() must be called in order to release underlying resources held by the object. Updated in version 1.17.0.
public class Connection
- Inheritance
-
java.lang.ObjectAutoCloseableConnection
Fields
| connected |
The Connected event to indicate that the recognizer is connected to service. In order to receive the connected event after subscribing to it, the Connection object itself needs to be alive. If the Connection object owning this event is out of its life time, all subscribed events won't be delivered. |
| disconnected |
The Disconnected event to indicate that the recognizer is disconnected from service. In order to receive the disconnected event after subscribing to it, the Connection object itself needs to be alive. If the Connection object owning this event is out of its life time, all subscribed events won't be delivered. |
| messageReceived |
The MessageReceived event indicates that the service has sent a network message to the client. Added in version 1.15.0. |
Methods
| close() |
Dispose of associated resources. close() must be called to relinquish underlying resources correctly. |
| closeConnection() |
Closes the connection the service. Users can optionally call closeConnection() to manually shutdown the connection of the associated Recognizer. The call might fail, depending on the process state of the Recognizer. But the failure does not affect the state of the associated Recognizer. |
| fromConversationTranslator(ConversationTranslator conversationTranslator) |
Gets the Connection instance from the conversation translator. |
| fromDialogServiceConnector(DialogServiceConnector dialogServiceConnector) |
Gets the Connection instance from the dialog service connector. |
| fromRecognizer(Recognizer recognizer) |
Gets the Connection instance from the specified recognizer. |
| fromSpeechSynthesizer(SpeechSynthesizer speechSynthesizer) |
Gets the Connection instance from the speech synthesizer. Added in version 1.17.0 |
| openConnection(boolean forContinuousRecognition) |
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 OpenConnection() might fail, depending on the process state of the Recognizer. But the failure does not affect the state of the associated Recognizer. Note: On return, the connection might not be ready yet. Please subscribe to the Connected event to be notified when the connection is established. |
| sendMessageAsync(String path, String payload) |
Sends a message to service. Added in version 1.7.0 Note: This method doesn't work for the connection of SpeechSynthesizer. |
| setMessageProperty(String path, String propertyName, String propertyValue) |
Appends a parameter in a message to service. Added in version 1.7.0 Note: This method doesn't work for the connection of SpeechSynthesizer. |