Thanks for tuning in to Google I/O. View all sessions on demand
Watch on demand
AudioClassifier
Stay organized with collections
Save and categorize content based on your preferences.
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.
- Input audio tensor (
kTfLiteFloat32
)
- input audio buffer of size
[batch x samples]
.
- batch inference is not supported (
batch
is required to be 1).
Output score tensor (kTfLiteFloat32
)
- with
N
classes of either 2 or 4 dimensions, such as [1 x N]
or [1 x 1 x 1 x N]
- the label file is required to be packed to the metadata. See the example of
creating metadata for an image classifier. If no label files are packed, it will
use index as label in the result.
See
an example
of such model, and
a
CLI demo tool for easily trying out this API.
Inherited Methods
From class
java.lang.Object
boolean
|
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
From interface
java.io.Closeable
From interface
java.lang.AutoCloseable
Public Methods
Performs actual classification on the provided audio tensor.
Parameters
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. |
public
AudioRecord
createAudioRecord
()
public
static
AudioClassifier
createFromFile
(Context context, String modelPath)
Parameters
context |
|
modelPath |
path of the classification model with metadata in the assets |
public
static
AudioClassifier
createFromFile
(File modelFile)
Parameters
modelFile |
the classification model File instance |
Parameters
context |
|
modelPath |
path of the classification model with metadata in the assets |
options |
|
Parameters
modelFile |
the classification model File instance |
options |
|
Creates a TensorAudio
instance to store input audio samples.
Returns the required input buffer size in number of float elements.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2021-10-15 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]