Introducing LiteRT : Google's high-performance runtime for on-device AI, formerly known as TensorFlow Lite.
Learn more
Send feedback
tflite_support.task.audio.TensorAudio
Stay organized with collections
Save and categorize content based on your preferences.
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.
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-05-08 UTC.
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"Missing the information I need"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"Too complicated / too many steps"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"Out of date"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"Samples / code issue"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
Need to tell us more?
{"lastModified": "Last updated 2024-05-08 UTC."}
[[["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."],[],[]]