Class DialogServiceConnector

  • All Implemented Interfaces:
    AutoCloseable

    public class DialogServiceConnector
    extends Object
    implements AutoCloseable
    Class that defines a DialogServiceConnector. Note: close() must be called in order to release underlying resources held by the object.
    • Constructor Detail

      • DialogServiceConnector

        public DialogServiceConnector​(DialogServiceConfig config)
        Builds a DialogServiceConnector with audio from default microphone input
        Parameters:
        config - Dialog service connector configuration.
      • DialogServiceConnector

        public DialogServiceConnector​(DialogServiceConfig config,
                                      AudioConfig audioConfig)
        Builds a DialogServiceConnector
        Parameters:
        config - Dialog service connector configuration.
        audioConfig - An optional audio input configuration associated with the recognizer
    • Method Detail

      • setAuthorizationToken

        public void setAuthorizationToken​(String token)
        Sets the authorization token used to communicate with the service. Note: The caller needs to ensure that the authorization token is valid. Before the authorization token expires, the caller needs to refresh it by calling this setter with a new valid token. Otherwise, the recognizer will encounter errors during recognition.
        Parameters:
        token - Authorization token.
      • getAuthorizationToken

        public String getAuthorizationToken()
        Gets the authorization token used to communicate with the service.
        Returns:
        Authorization token.
      • getProperties

        public PropertyCollection getProperties()
        The collection of properties and their values defined for this DialogServiceConnector.
        Returns:
        The collection of properties and their values defined for this DialogServiceConnector.
      • connectAsync

        public Future<Void> connectAsync()
        Connects with the service.
        Returns:
        A task representing the asynchronous operation that connects to the service.
      • disconnectAsync

        public Future<Void> disconnectAsync()
        Disconnects from the service.
        Returns:
        A task representing the asynchronous operation that disconnects from the service.
      • sendActivityAsync

        public Future<String> sendActivityAsync​(String activity)
        Sends an activity to the backing dialog.
        Parameters:
        activity - Activity to be sent.
        Returns:
        A task representing the asynchronous operation that sends an activity to the backing dialog.
      • setSpeechActivityTemplate

        public void setSpeechActivityTemplate​(String activityTemplate)
        Sets the JSON template that will be provided to the speech service for the next conversation. The service will attempt to merge this template into all activities sent to the dialog backend, whether originated by the client with SendActivityAsync or generated by the service, as is the case with speech-to-text results.
        Parameters:
        activityTemplate - The JSON payload to be merged into generated activity messages.
      • listenOnceAsync

        public Future<SpeechRecognitionResult> listenOnceAsync()
        Starts a listening session that will terminate after the first utterance.
        Returns:
        A task representing the asynchronous operation that starts a one shot listening session.
      • stopListeningAsync

        public Future<Void> stopListeningAsync()
        Requests that an active listening operation immediately finish, interrupting any ongoing speaking, and provide a result reflecting whatever audio data has been captured so far.
        Returns:
        A task representing the asynchronous operation that stops an active listening session.
      • startKeywordRecognitionAsync

        public Future<Void> startKeywordRecognitionAsync​(KeywordRecognitionModel model)
        Initiates keyword recognition.
        Parameters:
        model - The keyword recognition model that specifies the keyword to be recognized.
        Returns:
        A task representing the asynchronous operation that starts keyword recognition.
      • stopKeywordRecognitionAsync

        public Future<Void> stopKeywordRecognitionAsync()
        Stop keyword recognition.
        Returns:
        A task representing the asynchronous operation that stops keyword recognition.
      • getImpl

        public SafeHandle getImpl()
        Returns the internal dialog service connector instance.
        Returns:
        The internal dialog service connector instance
      • close

        public void close()
        Dispose of associated resources. Note: close() must be called in order to release underlying resources held by the object.
        Specified by:
        close in interface AutoCloseable