AudioClassifier.AudioClassifierOptions.Builder

public static abstract class AudioClassifier.AudioClassifierOptions.Builder

Public Constructors

Public Methods

final AudioClassifier.AudioClassifierOptions
build()
Validates and builds the AudioClassifier.AudioClassifierOptions instance.
abstract AudioClassifier.AudioClassifierOptions.Builder
setBaseOptions(BaseOptions baseOptions)
Sets the BaseOptions for the audio classifier task.
abstract AudioClassifier.AudioClassifierOptions.Builder
setCategoryAllowlist(List<String> categoryAllowlist)
Sets the optional allowlist of category names.
abstract AudioClassifier.AudioClassifierOptions.Builder
setCategoryDenylist(List<String> categoryDenylist)
Sets the optional denylist of category names.
abstract AudioClassifier.AudioClassifierOptions.Builder
setDisplayNamesLocale(String locale)
Sets the optional locale to use for display names specified through the TFLite Model Metadata, if any.
abstract AudioClassifier.AudioClassifierOptions.Builder
setErrorListener(ErrorListener errorListener)
Sets an optional ErrorListener.
abstract AudioClassifier.AudioClassifierOptions.Builder
setMaxResults(Integer maxResults)
Sets the optional maximum number of top-scored classification results to return.
abstract AudioClassifier.AudioClassifierOptions.Builder
setResultListener(PureResultListener<AudioClassifierResult> resultListener)
Sets the OutputHandler.ResultListener to receive the classification results asynchronously when the audio classifier is in the audio stream mode.
abstract AudioClassifier.AudioClassifierOptions.Builder
setRunningMode(RunningMode runningMode)
Sets the RunningMode for the audio classifier task.
abstract AudioClassifier.AudioClassifierOptions.Builder
setScoreThreshold(Float scoreThreshold)
Sets the optional score threshold.

Inherited Methods

Public Constructors

public Builder ()

Public Methods

public final AudioClassifier.AudioClassifierOptions build ()

Validates and builds the AudioClassifier.AudioClassifierOptions instance.

Throws
IllegalArgumentException if any of the set options are invalid.

public abstract AudioClassifier.AudioClassifierOptions.Builder setBaseOptions (BaseOptions baseOptions)

Sets the BaseOptions for the audio classifier task.

Parameters
baseOptions

public abstract AudioClassifier.AudioClassifierOptions.Builder setCategoryAllowlist (List<String> categoryAllowlist)

Sets the optional allowlist of category names.

If non-empty, detection results whose category name is not in this set will be filtered out. Duplicate or unknown category names are ignored. Mutually exclusive with categoryDenylist.

Parameters
categoryAllowlist

public abstract AudioClassifier.AudioClassifierOptions.Builder setCategoryDenylist (List<String> categoryDenylist)

Sets the optional denylist of category names.

If non-empty, detection results whose category name is in this set will be filtered out. Duplicate or unknown category names are ignored. Mutually exclusive with categoryAllowlist.

Parameters
categoryDenylist

public abstract AudioClassifier.AudioClassifierOptions.Builder setDisplayNamesLocale (String locale)

Sets the optional locale to use for display names specified through the TFLite Model Metadata, if any.

Parameters
locale

public abstract AudioClassifier.AudioClassifierOptions.Builder setErrorListener (ErrorListener errorListener)

Sets an optional ErrorListener.

Parameters
errorListener

public abstract AudioClassifier.AudioClassifierOptions.Builder setMaxResults (Integer maxResults)

Sets the optional maximum number of top-scored classification results to return.

If not set, all available results are returned. If set, must be > 0.

Parameters
maxResults

public abstract AudioClassifier.AudioClassifierOptions.Builder setResultListener (PureResultListener<AudioClassifierResult> resultListener)

Sets the OutputHandler.ResultListener to receive the classification results asynchronously when the audio classifier is in the audio stream mode.

Parameters
resultListener

public abstract AudioClassifier.AudioClassifierOptions.Builder setRunningMode (RunningMode runningMode)

Sets the RunningMode for the audio classifier task. Default to the audio clips mode. Image classifier has two modes:

  • AUDIO_CLIPS: The mode for running audio classification on audio clips. Users feed audio clips to the `classify` method, and will receive the classification results as the return value.
  • AUDIO_STREAM: The mode for running audio classification on the audio stream, such as from microphone. Users call `classifyAsync` to push the audio data into the AudioClassifier, the classification results will be available in the result callback when the audio classifier finishes the work.

Parameters
runningMode