AudioClassifier.AudioClassifierOptions.Builder

public abstract class AudioClassifier.AudioClassifierOptions.Builder


Builder for AudioClassifierOptions.

Summary

Public constructors

Public methods

final AudioClassifier.AudioClassifierOptions

Validates and builds the AudioClassifierOptions instance.

abstract AudioClassifier.AudioClassifierOptions.Builder

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

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

abstract AudioClassifier.AudioClassifierOptions.Builder

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

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

abstract AudioClassifier.AudioClassifierOptions.Builder

Sets the RunningMode for the audio classifier task.

abstract AudioClassifier.AudioClassifierOptions.Builder
setScoreThreshold(Float scoreThreshold)

Sets the optional score threshold.

Public constructors

Builder

public Builder()

Public methods

build

public final AudioClassifier.AudioClassifierOptions build()

Validates and builds the AudioClassifierOptions instance.

Throws
java.lang.IllegalArgumentException

if any of the set options are invalid.

setBaseOptions

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

Sets the BaseOptions for the audio classifier task.

setCategoryAllowlist

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.

setCategoryDenylist

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.

setDisplayNamesLocale

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.

setErrorListener

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

Sets an optional ErrorListener.

setMaxResults

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.

setResultListener

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

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

setRunningMode

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.

setScoreThreshold

public abstract AudioClassifier.AudioClassifierOptions.Builder setScoreThreshold(Float scoreThreshold)

Sets the optional score threshold. Results with score below this value are rejected.

Overrides the score threshold specified in the TFLite Model Metadata, if any.