A wrapper class to store the input audio.
tflite_support.task.audio.TensorAudio(
audio_format: tflite_support.task.audio.AudioFormat
,
buffer_size: int
) -> None
Args |
audio_format
|
format of the audio.
|
buffer_size
|
buffer size of the audio.
|
Attributes |
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()
Clear the internal buffer and fill it with zeros.
create_from_wav_file
View source
@classmethod
create_from_wav_file(
file_name: str, sample_count: int, offset: int = 0
) -> 'TensorAudio'
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.
|
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.
|
RuntimeError
|
If other types of error occurred.
|
load_from_array
View source
load_from_array(
src: np.ndarray, offset: int = 0, size: int = -1
) -> None
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
load_from_audio_record(
record: tflite_support.task.audio.AudioRecord
) -> None
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.
|