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.
Returns
TensorAudio object.
Raises
ValueError
If an input parameter, such as the audio file, is invalid.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-05-08 UTC."],[],[],null,["# tflite_support.task.audio.TensorAudio\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [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) |\n\nA wrapper class to store the input audio. \n\n tflite_support.task.audio.TensorAudio(\n audio_format: ../../../tflite_support/task/audio/AudioFormat,\n buffer_size: int\n ) -\u003e None\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|----------------|---------------------------|\n| `audio_format` | format of the audio. |\n| `buffer_size` | buffer size of the audio. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Attributes ---------- ||\n|---------------|-------------------------------------|\n| `buffer` | Gets the internal buffer. |\n| `buffer_size` | Gets the sample count of the audio. |\n| `format` | Gets the audio format of the audio. |\n\n\u003cbr /\u003e\n\nMethods\n-------\n\n### `clear`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L40-L42) \n\n clear()\n\nClear the internal buffer and fill it with zeros.\n\n### `create_from_wav_file`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L44-L75) \n\n @classmethod\n create_from_wav_file(\n file_name: str, sample_count: int, offset: int = 0\n ) -\u003e 'TensorAudio'\n\nCreates `TensorAudio` object from the WAV file.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `file_name` | WAV file name. |\n| `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. |\n| `offset` | An optional offset for allowing the user to skip a certain number samples at the beginning. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ||\n|---|---|\n| `TensorAudio` object. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|------------------------------------------------------------|\n| `ValueError` | If an input parameter, such as the audio file, is invalid. |\n| `RuntimeError` | If other types of error occurred. |\n\n\u003cbr /\u003e\n\n### `load_from_array`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L104-L144) \n\n load_from_array(\n src: np.ndarray, offset: int = 0, size: int = -1\n ) -\u003e None\n\nLoads the audio data from a NumPy array.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|-----------------------------------------------------------------------------------------|\n| `src` | A NumPy source array contains the input audio. |\n| `offset` | An optional offset for loading a slice of the `src` array to the buffer. |\n| `size` | An optional size parameter denoting the number of samples to load from the `src` array. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|--------------|----------------------------------------------------------------------------------------------------------|\n| `ValueError` | If the input array has an incorrect shape or if `offset` + `size` exceeds the length of the `src` array. |\n\n\u003cbr /\u003e\n\n### `load_from_audio_record`\n\n[View source](https://github.com/tensorflow/tflite-support/blob/v0.4.4/tensorflow_lite_support/python/task/audio/core/tensor_audio.py#L77-L102) \n\n load_from_audio_record(\n record: ../../../tflite_support/task/audio/AudioRecord\n ) -\u003e None\n\nLoads audio data from an AudioRecord instance.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ||\n|----------|--------------------------|\n| `record` | An AudioRecord instance. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ||\n|----------------|-------------------------------------------------|\n| `ValueError` | Raised if the audio record's config is invalid. |\n| `RuntimeError` | Raised if other types of error occurred. |\n\n\u003cbr /\u003e"]]