Package com.keenresearch.keenasr
Class KASRResponse
java.lang.Object
com.keenresearch.keenasr.KASRResponse
- All Implemented Interfaces:
AutoCloseable
KASRResponse contains various metadata related to the single interaction with the speech
recognition system, from calling startListening until the recognizer stopped listening. It is
provided to the application via onFinalResponse callback method.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Releases the native resources associated with this response.final Stringfinal Stringfinal KASRResultfinal Stringfinal KASRAudioQualityResultfinal Stringfinal floatfinal booleanfinal StringgetJson()final Stringfinal Stringfinal floatfinal Stringfinal ZonedDateTimefinal BooleanQueues audio and json from this response for an upload to Dashboard.final BooleanSave audio file in the directory passed via directory input variable.final BooleanSave json file in the directory passed via directory input variable.final BooleansetCustomJson(String json) Sets a custom JSON object to be merged into this response's JSON representation.
-
Method Details
-
getAsrResult
- Returns:
- An instance of KASRResult, which contains ASR result for this response
-
getAudioQualityResult
- Returns:
- An instance of KASRAudioQualityResult, which contains audio quality metrics for this response
-
getJson
- Returns:
- String object with JSON representation of the response
-
getEchoCancellation
public final boolean getEchoCancellation()- Returns:
- True if echo cancellation was set to true, false otherwise
-
getStartTime
- Returns:
- LocalDateTime object that specifies the date/time when this response was created (in current device timezone).
-
getResponseId
- Returns:
- Unique identifier of this response
-
getDecodingGraphName
- Returns:
- String representing decoding graph name that was used when creating this response
-
getAsrBundleName
- Returns:
- String object representing the name of the ASR Bundle that was used to initialize the recognizer.
-
getSdkVersion
- Returns:
- String object with the version of KeenASR SDK.
-
getAppBundleId
- Returns:
- String object with the bundleID/packageName of the app that created the response.
-
getSampleRate
public final float getSampleRate()- Returns:
- sampling rate (in Hertz) with which the audio was captured.
-
getDuration
public final float getDuration()- Returns:
- Duration of the response in seconds.
-
getAudioFilename
- Returns:
- Filename of the audio file that contains audio that corresponds to this response.
Filename will typically be in the format responseID.wav. This value is relevant only if you
used
saveAudio(java.io.File)method.
-
getJsonFilename
- Returns:
- Filename of the JSON file that contains information relevant to this response.
Filename will typically be in the format responseID.json. This value is relevant only if you
use
saveJson(java.io.File)method.
-
setCustomJson
Sets a custom JSON object to be merged into this response's JSON representation. Each call replaces any previously set custom JSON.- Parameters:
json- String representation of a JSON value. Must be well-formed JSON, or this method returns false and the response is unchanged. Passnullto receive false without effect.- Returns:
- true if the JSON was accepted and stored; false if
json - Throws:
IllegalStateException- if this response has been closed.
-
saveAudio
Save audio file in the directory passed via directory input variable. It is developer responsibility to discard the file eventually and free the disk space. The file with name obtained viagetAudioFilename()will be saved in the directory passed to this method.- Parameters:
directory- File object pointing to the directory in which to save the audio file.- Returns:
- True if the file was successfully saved, false otherwise. This method will typically fail if the directory is not writable or if there is not enough disk space to save the file.
- Throws:
IllegalStateException- if this response has been closed
-
saveJson
Save json file in the directory passed via directory input variable. It is developer responsibility to discard the file eventually and free disk space. The file with name obtained via KASRResponse#getJsonFilename} will be saved in the directory passed to this method.- Parameters:
directory- File object pointing to the directory in which to save the JSON file.- Returns:
- True if the file was successfully saved, false otherwise. This method will typically fail if the directory is not writable or if there is not enough disk space to save the file.
- Throws:
IllegalStateException- if this response has been closed
-
queueForUpload
Queues audio and json from this response for an upload to Dashboard. This method will only place audio and json in an internal directory that's scanned by the KASRUploder background thread. If KASRUploader background thread is not setup, the files will never be removed. With KASRUploader background thread running, the files will be uploaded to the Keen Research Dashboard service as long as internet connectivity is available.- Returns:
- true if files were queued for the upload, false otherwise.
- Throws:
IllegalStateException- if this response has been closed
-
close
public void close()Releases the native resources associated with this response. After calling this method, any methods that access native data (e.g.saveJson(java.io.File),saveAudio(java.io.File),queueForUpload()) will throwIllegalStateException.This method is idempotent — calling it multiple times has no effect. It is also called by the finalizer as a safety net, but callers should not rely on finalization for timely resource cleanup.
- Specified by:
closein interfaceAutoCloseable
-