共用方式為


Connection Class

Definition

A proxy class for managing connection to the speech service of the specified Recognizer. Added in 1.2.0

public sealed class Connection : IDisposable
type Connection = class
    interface IDisposable
Public NotInheritable Class Connection
Implements IDisposable
Inheritance
Connection
Implements

Remarks

By default, a Recognizer autonomously manages connection to service when needed. The Connection class provides additional methods you can use 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. You can optionally call Open() to manually initiate a service connection before starting recognition on the Recognizer associated with this Connection. After starting a recognition, calling Open() or Close() 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.

Methods

Close()

Closes the connection the service. You can optionally call Close() 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.

Dispose()

Dispose of associated resources.

Finalize()
FromConversationTranslator(ConversationTranslator)

Gets the Connection instance from the conversation translator.

FromDialogServiceConnector(DialogServiceConnector)

Gets the Connection instance from the specified dialog service connector, used for observing and managing connection and disconnection from the speech service.

FromRecognizer(Recognizer)

Gets the Connection instance from the specified recognizer.

FromSpeechSynthesizer(SpeechSynthesizer)

Gets the Connection instance from the specified speech synthesizer, used for observing and managing connection and disconnection from the speech service. Added in version 1.17.0

Open(Boolean)

Starts to set up connection to the service. You can optionally call Open() to manually set up a connection in advance before starting recognition on the Recognizer associated with this Connection. After starting recognition, calling Open() 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, Byte[], UInt32)

Sends a binary message to the speech service as an asynchronous operation. Note: This method doesn't work for the connection of SpeechSynthesizer. Added in 1.10.0

SendMessageAsync(String, String)

Sends a message to the Speech service as an asynchronous operation. Added in 1.7.0

SetMessageProperty(String, String, String)

Appends a parameter in a message to service. Added in 1.7.0

Events

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.

Applies to