<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/audio_classifier.py#L33-L168) |

Writes metadata into an audio classifier.

Inherits From: [`MetadataWriter`](https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_writers/audio_classifier/metadata_writer/MetadataWriter)

    tflite_support.metadata_writers.audio_classifier.MetadataWriter(
        model_buffer: bytearray,
        metadata_buffer: Optional[bytearray] = None,
        associated_files: Optional[List[str]] = None
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `model_buffer` | valid buffer of the model file. |
| `metadata_buffer` | valid buffer of the metadata. |
| `associated_files` | path to the associated files to be populated. |

<br />

## Methods

### `create_for_inference`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/audio_classifier.py#L112-L168)

    @classmethod
    create_for_inference(
        model_buffer: bytearray,
        sample_rate: int,
        channels: int,
        label_file_paths: List[str],
        score_calibration_md: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_writers/metadata_info/ScoreCalibrationMd] = None
    )

Creates mandatory metadata for TFLite Support inference.

The parameters required in this method are mandatory when using TFLite
Support features, such as Task library and Codegen tool (Android Studio ML
Binding). Other metadata fields will be set to default. If other fields need
to be filled, use the method `create_from_metadata_info` to edit them.

<br />

<br />

<br />

| Args ||
|---|---|
| `model_buffer` | valid buffer of the model file. |
| `sample_rate` | the sample rate in Hz when the audio was captured. |
| `channels` | the channel count of the audio. |
| `label_file_paths` | paths to the label files [1](https://github.com/tensorflow/tflite-support/blob/b2a509716a2d71dfff706468680a729cc1604cff/tensorflow_lite_support/metadata/metadata_schema.fbs#L605-L612) in the classification tensor. Pass in an empty list if the model does not have any label file. |
| `score_calibration_md` | information of the score calibration operation [2](https://github.com/tensorflow/tflite-support/blob/b80289c4cd1224d0e1836c7654e82f070f9eefaa/tensorflow_lite_support/metadata/metadata_schema.fbs#L590) in the classification tensor. Optional if the model does not use score calibration. <br /> <br /> |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A MetadataWriter object. ||

<br />

### `create_from_metadata`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/metadata_writer.py#L92-L162)

    @classmethod
    create_from_metadata(
        model_buffer: bytearray,
        model_metadata: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_schema_py_generated/ModelMetadataT] = None,
        input_metadata: Optional[List[_metadata_fb.TensorMetadataT]] = None,
        output_metadata: Optional[List[_metadata_fb.TensorMetadataT]] = None,
        associated_files: Optional[List[str]] = None,
        input_process_units: Optional[List[_metadata_fb.ProcessUnitT]] = None,
        output_process_units: Optional[List[_metadata_fb.ProcessUnitT]] = None
    )

Creates MetadataWriter based on the metadata Flatbuffers Python Objects.

<br />

<br />

<br />

| Args ||
|---|---|
| `model_buffer` | valid buffer of the model file. |
| `model_metadata` | general model metadata [1](https://github.com/tensorflow/tflite-support/blob/b2a509716a2d71dfff706468680a729cc1604cff/tensorflow_lite_support/metadata/metadata_schema.fbs#L605-L612). The subgraph_metadata will be refreshed with input_metadata and output_metadata. |
| `input_metadata` | a list of metadata of the input tensors [2](https://github.com/tensorflow/tflite-support/blob/b80289c4cd1224d0e1836c7654e82f070f9eefaa/tensorflow_lite_support/metadata/metadata_schema.fbs#L590). |
| `output_metadata` | a list of metadata of the output tensors [3](https://github.com/tensorflow/tflite-support/blob/b80289c4cd1224d0e1836c7654e82f070f9eefaa/tensorflow_lite_support/metadata/metadata_schema.fbs#L599). |
| `associated_files` | path to the associated files to be populated. |
| `input_process_units` | a lits of metadata of the input process units [4](https://github.com/tensorflow/tflite-support/blob/b5cc57c74f7990d8bc055795dfe8d50267064a57/tensorflow_lite_support/metadata/metadata_schema.fbs#L646). |
| `output_process_units` | a lits of metadata of the output process units [5](https://github.com/tensorflow/tflite-support/blob/b5cc57c74f7990d8bc055795dfe8d50267064a57/tensorflow_lite_support/metadata/metadata_schema.fbs#L650). <br /> <br /> |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A MetadataWriter Object. ||

<br />

### `create_from_metadata_info`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/audio_classifier.py#L36-L62)

    @classmethod
    create_from_metadata_info(
        model_buffer: bytearray,
        general_md: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_writers/metadata_info/GeneralMd] = None,
        input_md: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_writers/metadata_info/InputAudioTensorMd] = None,
        output_md: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_writers/metadata_info/ClassificationTensorMd] = None
    )

Creates MetadataWriter based on general/input/output information.

<br />

<br />

<br />

| Args ||
|---|---|
| `model_buffer` | valid buffer of the model file. |
| `general_md` | general information about the model. If not specified, default general metadata will be generated. |
| `input_md` | input audio tensor informaton. If not specified, default input metadata will be generated. |
| `output_md` | output classification tensor informaton. If not specified, default output metadata will be generated. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A MetadataWriter object. ||

<br />

### `create_from_metadata_info_for_multihead`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/audio_classifier.py#L64-L110)

    @classmethod
    create_from_metadata_info_for_multihead(
        model_buffer: bytearray,
        general_md: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_writers/metadata_info/GeneralMd] = None,
        input_md: Optional[https://developers.google.com/edge/api/tflite/python/tflite_support/metadata_writers/metadata_info/InputAudioTensorMd] = None,
        output_md_list: Optional[List[metadata_info.ClassificationTensorMd]] = None
    )

Creates a MetadataWriter instance for multihead models.

<br />

<br />

<br />

| Args ||
|---|---|
| `model_buffer` | valid buffer of the model file. |
| `general_md` | general information about the model. If not specified, default general metadata will be generated. |
| `input_md` | input audio tensor informaton. If not specified, default input metadata will be generated. |
| `output_md_list` | information of each output tensor head. If not specified, default metadata will be generated for each output tensor. If `tensor_name` in each `ClassificationTensorMd` instance is not specified, elements in `output_md_list` need to have one-to-one mapping with the output tensors [1](https://github.com/tensorflow/tflite-support/blob/b2a509716a2d71dfff706468680a729cc1604cff/tensorflow_lite_support/metadata/metadata_schema.fbs#L605-L612) in the TFLite model. <br /> <br /> |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| A MetadataWriter object. ||

<br />

### `get_metadata_json`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/metadata_writer.py#L183-L194)

    get_metadata_json() -> str

Gets the generated JSON metadata string before populated into model.

This method returns the metadata buffer before populated into the model.
More fields could be filled by MetadataPopulator, such as
min_parser_version. Use get_populated_metadata_json() if you want to get the
final metadata string.

<br />

<br />

<br />

| Returns ||
|---|---|
| The generated JSON metadata string before populated into model. ||

<br />

### `get_populated_metadata_json`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/metadata_writer.py#L196-L207)

    get_populated_metadata_json() -> str

Gets the generated JSON metadata string after populated into model.

More fields could be filled by MetadataPopulator, such as
min_parser_version. Use get_metadata_json() if you want to get the
original metadata string.

<br />

<br />

<br />

| Returns ||
|---|---|
| The generated JSON metadata string after populated into model. ||

<br />

### `populate`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/metadata/python/metadata_writers/metadata_writer.py#L164-L181)

    populate() -> bytearray

Populates the metadata and label file to the model file.

<br />

<br />

<br />

| Returns ||
|---|---|
| A new model buffer with the metadata and associated files. ||

<br />