Performs classification on audio waveforms.
The API expects a TFLite model with TFLite Model Metadata..
The API supports models with one audio input tensor and one classification output tensor. To be more specific, here are the requirements.
kTfLiteFloat32)
[batch x samples].
batch is required to be 1).
kTfLiteFloat32)
N classes of either 2 or 4 dimensions, such as [1 x N] or [1 x 1 x 1 x N]
| class | AudioClassifier.AudioClassifierOptions | Options for setting up an AudioClassifier. |
|
Performs actual classification on the provided audio tensor.
| tensor | a TensorAudio containing the input audio clip in float with values
between [-1, 1). The tensor argument should have the same flat size as the TFLite
model's input tensor. It's recommended to create tensor using createInputTensorAudio method. |
|---|
| IllegalArgumentException | if an argument is invalid |
|---|---|
| IllegalStateException | if error occurs when classifying the audio clip from the native code |
Creates an AudioRecord instance to record audio stream. The returned
AudioRecord instance is initialized and client needs to call AudioRecord.startRecordingnull method to start recording.
AudioRecord instance in AudioRecord.STATE_INITIALIZED| IllegalArgumentException | if the model required channel count is unsupported |
|---|---|
| IllegalStateException | if AudioRecord instance failed to initialize |
Creates an AudioClassifier instance with a model buffer and the default AudioClassifier.AudioClassifierOptions.
| modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the
classification model |
|---|
| IllegalStateException | if there is an internal error |
|---|---|
| RuntimeException | if there is an otherwise unspecified error |
| IllegalArgumentException | if the model buffer is not a direct ByteBuffer or a
MappedByteBuffer
|
Creates an AudioClassifier instance with a model buffer and AudioClassifier.AudioClassifierOptions.
| modelBuffer | a direct ByteBuffer or a MappedByteBuffer of the
classification model |
|---|---|
| options |
| IllegalStateException | if there is an internal error |
|---|---|
| RuntimeException | if there is an otherwise unspecified error |
| IllegalArgumentException | if the model buffer is not a direct ByteBuffer or a
MappedByteBuffer
|
Creates an AudioClassifier instance from the default AudioClassifier.AudioClassifierOptions.
| context | |
|---|---|
| modelPath | path of the classification model with metadata in the assets |
| IOException | if an I/O error occurs when loading the tflite model |
|---|---|
| IllegalArgumentException | if an argument is invalid |
| IllegalStateException | if there is an internal error |
| RuntimeException | if there is an otherwise unspecified error |
Creates an AudioClassifier instance from the default AudioClassifier.AudioClassifierOptions.
| modelFile | the classification model File instance |
|---|
| IOException | if an I/O error occurs when loading the tflite model |
|---|---|
| IllegalArgumentException | if an argument is invalid |
| IllegalStateException | if there is an internal error |
| RuntimeException | if there is an otherwise unspecified error |
Creates an AudioClassifier instance from AudioClassifier.AudioClassifierOptions.
| context | |
|---|---|
| modelPath | path of the classification model with metadata in the assets |
| options |
| IOException | if an I/O error occurs when loading the tflite model |
|---|---|
| IllegalArgumentException | if an argument is invalid |
| IllegalStateException | if there is an internal error |
| RuntimeException | if there is an otherwise unspecified error |
Creates an AudioClassifier instance.
| modelFile | the classification model File instance |
|---|---|
| options |
| IOException | if an I/O error occurs when loading the tflite model |
|---|---|
| IllegalArgumentException | if an argument is invalid |
| IllegalStateException | if there is an internal error |
| RuntimeException | if there is an otherwise unspecified error |
Creates a TensorAudio instance to store input audio samples.
TensorAudio with the same size as model input tensor| IllegalArgumentException | if the model is not compatible |
|---|
Returns the required input buffer size in number of float elements.
Returns the TensorAudio.TensorAudioFormat required by the model.