Connection Class

Proxy class for managing the 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 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.

Note

Updated in version 1.17.0.

Constructor for internal use.

Inheritance
builtins.object
Connection

Constructor

Connection(handle: c_void_p)

Parameters

Name Description
handle
Required

Methods

close

Closes the connection the service. Users 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.

from_dialog_service_connector

Gets the Connection instance from the specified dialog service connector.

from_recognizer

Gets the Connection instance from the specified recognizer.

from_speech_synthesizer

Gets the Connection instance from the specified speech synthesizer.

Note

Added in version 1.17.0.

open

Starts to set up connection to the service. Users 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.

set_message_property

Appends a parameter in a message to service.

Note

This method doesn't work for the connection of SpeechSynthesizer.

close

Closes the connection the service. Users 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.

close()

from_dialog_service_connector

Gets the Connection instance from the specified dialog service connector.

from_dialog_service_connector(dialog_service_connector: DialogServiceConnector) -> Connection

Parameters

Name Description
dialog_service_connector
Required

from_recognizer

Gets the Connection instance from the specified recognizer.

from_recognizer(recognizer: Recognizer) -> Connection

Parameters

Name Description
recognizer
Required

from_speech_synthesizer

Gets the Connection instance from the specified speech synthesizer.

Note

Added in version 1.17.0.

from_speech_synthesizer(speech_synthesizer: SpeechSynthesizer) -> Connection

Parameters

Name Description
speech_synthesizer
Required

open

Starts to set up connection to the service. Users 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.

open(for_continuous_recognition: bool)

Parameters

Name Description
forContinuousRecognition
Required

indicates whether the connection is used for continuous recognition or single-shot recognition. It takes no effect if the connection is from SpeechSynthsizer.

for_continuous_recognition
Required

set_message_property

Appends a parameter in a message to service.

Note

This method doesn't work for the connection of SpeechSynthesizer.

set_message_property(path: str, property_name: str, property_value: str)

Parameters

Name Description
path
Required

The message path.

property_name
Required

The property name that you want to set.

property_value
Required

The value of the property that you want to set.

Attributes

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.