<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/python/task/audio/core/tensor_audio.py#L25-L159) |

A wrapper class to store the input audio.

    tflite_support.task.audio.TensorAudio(
        audio_format: https://developers.google.com/edge/api/tflite/python/tflite_support/task/audio/AudioFormat,
        buffer_size: int
    ) -> None

<br />

<br />

<br />

| ## Args ||
|---|---|
| `audio_format` | format of the audio. |
| `buffer_size` | buffer size of the audio. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `buffer` | Gets the internal buffer. |
| `buffer_size` | Gets the sample count of the audio. |
| `format` | Gets the audio format of the audio. |

<br />

## Methods

### `clear`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L40-L42)

    clear()

Clear the internal buffer and fill it with zeros.

### `create_from_wav_file`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L44-L75)

    @classmethod
    create_from_wav_file(
        file_name: str, sample_count: int, offset: int = 0
    ) -> 'TensorAudio'

Creates `TensorAudio` object from the WAV file.

<br />

<br />

<br />

| Args ||
|---|---|
| `file_name` | WAV file name. |
| `sample_count` | The number of samples to read from the WAV file. This value should match with the input size of the TensorFlow Lite audio model that will consume the created TensorAudio object. If the WAV file contains more samples than sample_count, only the samples at the beginning of the WAV file will be loaded. |
| `offset` | An optional offset for allowing the user to skip a certain number samples at the beginning. |

<br />

<br />

<br />

<br />

| Returns ||
|---|---|
| `TensorAudio` object. ||

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If an input parameter, such as the audio file, is invalid. |
| `RuntimeError` | If other types of error occurred. |

<br />

### `load_from_array`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L104-L144)

    load_from_array(
        src: np.ndarray, offset: int = 0, size: int = -1
    ) -> None

Loads the audio data from a NumPy array.

<br />

<br />

<br />

| Args ||
|---|---|
| `src` | A NumPy source array contains the input audio. |
| `offset` | An optional offset for loading a slice of the `src` array to the buffer. |
| `size` | An optional size parameter denoting the number of samples to load from the `src` array. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | If the input array has an incorrect shape or if `offset` + `size` exceeds the length of the `src` array. |

<br />

### `load_from_audio_record`

[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L77-L102)

    load_from_audio_record(
        record: https://developers.google.com/edge/api/tflite/python/tflite_support/task/audio/AudioRecord
    ) -> None

Loads audio data from an AudioRecord instance.

<br />

<br />

<br />

| Args ||
|---|---|
| `record` | An AudioRecord instance. |

<br />

<br />

<br />

<br />

| Raises ||
|---|---|
| `ValueError` | Raised if the audio record's config is invalid. |
| `RuntimeError` | Raised if other types of error occurred. |

<br />