Class DialogServiceConnector
- java.lang.Object
-
- com.microsoft.cognitiveservices.speech.dialog.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.
-
-
Field Summary
Fields Modifier and Type Field Description EventHandlerImpl<ActivityReceivedEventArgs>activityReceivedDefines event handler for the activity received event.EventHandlerImpl<SpeechRecognitionCanceledEventArgs>canceledDefines event handler for the canceled event.EventHandlerImpl<SpeechRecognitionEventArgs>recognizedDefines event handler for the recognized event.EventHandlerImpl<SpeechRecognitionEventArgs>recognizingDefines event handler for the recognizing event.EventHandlerImpl<SessionEventArgs>sessionStartedDefines event handler for the session start event.EventHandlerImpl<SessionEventArgs>sessionStoppedDefines event handler for the session stop event.EventHandlerImpl<RecognitionEventArgs>speechEndDetectedDefines event handler for the speech end detection event.EventHandlerImpl<RecognitionEventArgs>speechStartDetectedDefines event handler for the speech start detection event.EventHandlerImpl<TurnStatusReceivedEventArgs>turnStatusReceivedDefines event handler for the turn status received event.
-
Constructor Summary
Constructors Constructor Description DialogServiceConnector(DialogServiceConfig config)Builds a DialogServiceConnector with audio from default microphone inputDialogServiceConnector(DialogServiceConfig config, AudioConfig audioConfig)Builds a DialogServiceConnector
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Dispose of associated resources.Future<Void>connectAsync()Connects with the service.Future<Void>disconnectAsync()Disconnects from the service.StringgetAuthorizationToken()Gets the authorization token used to communicate with the service.SafeHandlegetImpl()Returns the internal dialog service connector instance.PropertyCollectiongetProperties()The collection of properties and their values defined for this DialogServiceConnector.Future<SpeechRecognitionResult>listenOnceAsync()Starts a listening session that will terminate after the first utterance.Future<String>sendActivityAsync(String activity)Sends an activity to the backing dialog.voidsetAuthorizationToken(String token)Sets the authorization token used to communicate with the service.voidsetSpeechActivityTemplate(String activityTemplate)Sets the JSON template that will be provided to the speech service for the next conversation.Future<Void>startKeywordRecognitionAsync(KeywordRecognitionModel model)Initiates keyword recognition.Future<Void>stopKeywordRecognitionAsync()Stop keyword recognition.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.
-
-
-
Field Detail
-
recognizing
public EventHandlerImpl<SpeechRecognitionEventArgs> recognizing
Defines event handler for the recognizing event.
-
recognized
public EventHandlerImpl<SpeechRecognitionEventArgs> recognized
Defines event handler for the recognized event.
-
sessionStarted
public EventHandlerImpl<SessionEventArgs> sessionStarted
Defines event handler for the session start event.
-
sessionStopped
public EventHandlerImpl<SessionEventArgs> sessionStopped
Defines event handler for the session stop event.
-
speechStartDetected
public EventHandlerImpl<RecognitionEventArgs> speechStartDetected
Defines event handler for the speech start detection event.
-
speechEndDetected
public EventHandlerImpl<RecognitionEventArgs> speechEndDetected
Defines event handler for the speech end detection event.
-
canceled
public EventHandlerImpl<SpeechRecognitionCanceledEventArgs> canceled
Defines event handler for the canceled event.
-
activityReceived
public EventHandlerImpl<ActivityReceivedEventArgs> activityReceived
Defines event handler for the activity received event.
-
turnStatusReceived
public EventHandlerImpl<TurnStatusReceivedEventArgs> turnStatusReceived
Defines event handler for the turn status received event.
-
-
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:
closein interfaceAutoCloseable
-
-