Connection Class
- java.
lang. Object - com.
microsoft. cognitiveservices. speech. Connection
- com.
Implements
public final class Connection
implements java.lang.AutoCloseable
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.
Field Summary
Modifier and Type | Field and Description |
---|---|
final
Event |
connected
The Connected event to indicate that the recognizer is connected to service. |
final
Event |
disconnected
The Disconnected event to indicate that the recognizer is disconnected from service. |
final
Event |
messageReceived
The Message |
Method Summary
Modifier and Type | Method and Description |
---|---|
void |
close()
Dispose of associated resources. |
void |
closeConnection()
Closes the connection the service. |
static Connection |
fromConversationTranslator(ConversationTranslator conversationTranslator)
Gets the Connection instance from the conversation translator. |
static Connection |
fromDialogServiceConnector(DialogServiceConnector dialogServiceConnector)
Gets the Connection instance from the dialog service connector. |
static Connection |
fromRecognizer(Recognizer recognizer)
Gets the Connection instance from the specified recognizer. |
static Connection |
fromSpeechSynthesizer(SpeechSynthesizer speechSynthesizer)
Gets the Connection instance from the speech synthesizer. |
void |
openConnection(boolean forContinuousRecognition)
Starts to set up connection to the service. |
java.util.concurrent.Future<java.lang.Void> |
sendMessageAsync(String path, String payload)
Sends a message to service. |
void |
setMessageProperty(String path, String propertyName, String propertyValue)
Appends a parameter in a message to service. |
Methods inherited from java.lang.Object
Field Details
connected
public final EventHandlerImpl
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
public final EventHandlerImpl
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
public final EventHandlerImpl
The MessageReceived event indicates that the service has sent a network message to the client. Added in version 1.15.0.
Method Details
close
public void close()
Dispose of associated resources. close() must be called to relinquish underlying resources correctly.
closeConnection
public void 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
public static Connection fromConversationTranslator(ConversationTranslator conversationTranslator)
Gets the Connection instance from the conversation translator.
Parameters:
Returns:
fromDialogServiceConnector
public static Connection fromDialogServiceConnector(DialogServiceConnector dialogServiceConnector)
Gets the Connection instance from the dialog service connector.
Parameters:
Returns:
fromRecognizer
public static Connection fromRecognizer(Recognizer recognizer)
Gets the Connection instance from the specified recognizer.
Parameters:
Returns:
fromSpeechSynthesizer
public static Connection fromSpeechSynthesizer(SpeechSynthesizer speechSynthesizer)
Gets the Connection instance from the speech synthesizer. Added in version 1.17.0
Parameters:
Returns:
openConnection
public void 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.
Parameters:
sendMessageAsync
public Future
Sends a message to service. Added in version 1.7.0
Parameters:
Returns:
setMessageProperty
public void setMessageProperty(String path, String propertyName, String propertyValue)
Appends a parameter in a message to service. Added in version 1.7.0
Parameters:
Applies to
Azure SDK for Java