Google I/O is a wrap! Catch up on TensorFlow sessions View sessions

tflite_support.task.audio.TensorAudio

A wrapper class to store the input audio.

audio_format format of the audio.
buffer_size buffer size of the audio.

buffer Gets the internal buffer.
buffer_size Gets the sample count of the audio.
format Gets the audio format of the audio.

Methods

clear

View source

Clear the internal buffer and fill it with zeros.

create_from_wav_file

View source

Creates TensorAudio object from the WAV file.

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.

Returns
TensorAudio object.

Raises
ValueError If the audio file is invalid.
RuntimeError If other types of error occurred.

load_from_array

View source

Loads the audio data from a NumPy array.

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.

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

load_from_audio_record

View source

Loads audio data from an AudioRecord instance.

Args
record An AudioRecord instance.

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