Audio properties and filtering
This topic describes the audio property and filtering functions: IS_VALID_AUDIO, AUDIO_METADATA, AUDIO_DURATION, AUDIO_DURATION_FILTER, and AUDIO_SIZE_FILTER.
The functions in this topic are provided by the Python multimodal function library (VVR 11.8+). Load the module at the beginning of the SQL job before use:
LOAD MODULE python;
USE MODULES python, core;
Audio property functions validate and read audio metadata; filter functions return BOOLEAN, which can be used directly in WHERE condition clauses.
Function summary
|
Function |
Category |
Description |
|
|
Determines whether an encoded audio object can be further processed by probing the media header or fully decoding it at the specified check level. Returns a boolean.Suitable for validating external audio ingestion, batch replay, or as an ASR pre-check., for example first use |
|
|
|
Reads audio metadata such as sample rate, channel count, frame count, duration, format, codec, bitrate, and object size.Suitable for audio inventory, quality statistics, and routing by properties., for example choosing a preprocessing pipeline based on sample rate or identifying abnormal sources by format. |
|
|
|
Returns the audio duration in seconds.Suitable for bucketing by audio length, estimating processing cost, or planning split strategies., for example routing overly long recordings to fixed-length splitting and sending short recordings directly to ASR. |
|
|
|
Checks whether the audio duration lies within the specified closed interval. You can set only a lower bound, only an upper bound, or both.Suitable for filtering too-short or too-long samples before model inference or training., for example excluding recordings shorter than 1 second or blocking audio exceeding the model input limit. |
|
|
|
Checks the byte size of |
Audio properties and filtering
IS_VALID_AUDIO
Validates whether an encoded audio can be read. This function does not accept decoded waveforms.
IS_VALID_AUDIO(audio_input [, validation])
|
|
type |
defaultvalue |
|
|
|
|
Required |
Encoded audio bytes, a URI, or an audio segment reference. |
|
|
|
|
Validation mode: |
Return type: BOOLEAN NOT NULL.
-
Cases that return FALSE (can be used in WHERE clauses to filter dirty data):
-
If input is NULL
-
Recognizable media data errors such as byte-stream corruption, truncation, or unrecognized format.
-
-
Cases that raise exceptions and fail the job (preconditions must be satisfied outside the job):
-
URI cannot be accessed (path missing, permission denied, or network failure).
-
Invalid audio segment reference (out-of-bounds or malformed reference).
-
Missing dependency or a non-media internal error.
-
For URI or segment reference inputs, reachability must be ensured by the caller; do not rely on IS_VALID_AUDIO as a fallback filter.
-- Byte input: URI issues do not apply. Only media corruption is filtered
SELECT * FROM raw_audio WHERE IS_VALID_AUDIO(audio_bytes, 'decode');
-- URI input: An unreachable URI fails the job. It is not filtered out
SELECT * FROM audio_files WHERE IS_VALID_AUDIO(uri, 'decode');
The internal decoding limit for decode mode is fixed at 1 GiB, matching the default max_decoded_bytes of AUDIO_DECODE. It cannot be adjusted via parameters yet. Valid audio whose PCM decoded size exceeds 1 GiB is judged FALSE.
AUDIO_METADATA
Reads metadata from encoded audio or a waveform.
AUDIO_METADATA(audio_input)
|
|
type |
defaultvalue |
|
|
|
|
Required |
Audio to read metadata from. |
Return type: audio metadata ROW.
-
If input is
NULL. Returns the value below when the encoded audio is corrupt:NULL. Exceptions such as URI access failure, invalid waveforms, or dependency errors are still thrown. -
For an audio segment reference,
framesandduration_msis clipped to the referenced interval;sizestill reflects the size of the full encoded object. -
For an audio waveform,
format,codec,bit_rateandsizeNULL. -
This function has no
on_error.
-- Recommended: Use an explicit single call to avoid relying on optimizer behavior
SELECT
meta.sample_rate,
meta.duration_ms
FROM (
SELECT AUDIO_METADATA(audio_bytes) AS meta FROM raw_audio
);
-- Or use a CTE:
WITH decoded AS (
SELECT AUDIO_METADATA(audio_bytes) AS meta FROM raw_audio
)
SELECT meta.sample_rate, meta.duration_ms FROM decoded;
AUDIO_DURATION
Reads the audio duration.
AUDIO_DURATION(audio_input)
|
|
type |
defaultvalue |
|
|
|
|
Required |
Audio to read duration from. |
Return type: DOUBLE. Unit: seconds.
first obtains the millisecond duration and then divides by 1000.0. If input is NULL. Returns the value below when encoded data is corrupt or the duration cannot be determined: NULL. Non-media data errors such as URI access failure are still thrown. This function has no on_error.
SELECT AUDIO_DURATION(audio_bytes) AS duration_seconds
FROM raw_audio;
AUDIO_DURATION_FILTER
Checks whether the audio duration is within a specified closed interval.
AUDIO_DURATION_FILTER(audio_input, min_seconds [, max_seconds])
|
|
type |
defaultvalue |
|
|
|
|
Required |
Audio to filter. |
|
|
|
Required |
Minimum duration. Bound is inclusive and must be greater than or equal to 0. In the three-argument form, may be |
|
|
|
|
Maximum duration. Bound is inclusive and must be greater than or equal to 0. |
Return type: BOOLEAN NOT NULL.
At least one bound must be non- NULL. When both are specified, max_seconds Must be greater than or equal to min_seconds. If input is NULL. Returns the value below when the encoded audio is corrupt or the duration is unknown: FALSE. When only an upper bound is set, use NULL:
SELECT *
FROM raw_audio
WHERE AUDIO_DURATION_FILTER(
audio_bytes,
CAST(NULL AS DOUBLE),
30.0
);
AUDIO_SIZE_FILTER
Checks whether the byte length of an encoded audio object is within the specified closed interval. This function does not read or decode media content, so corrupt data whose size still matches the interval returns TRUE.
AUDIO_SIZE_FILTER(audio_input, min_bytes [, max_bytes])
|
|
type |
defaultvalue |
|
|
|
|
Required |
Encoded audio bytes or a URI. Segment references and audio waveforms are not supported. |
|
|
|
Required |
Minimum byte count. Bound is inclusive and must be greater than or equal to 0. In the three-argument form, may be |
|
|
|
|
Maximum byte count. Bound is inclusive and must be greater than or equal to 0. |
Return type: BOOLEAN NOT NULL.
At least one bound must be non- NULL. The upper bound must not be smaller than the lower bound. Byte inputs use the length directly; URI inputs read the file size. If the input is NULL, returns FALSE, the function returns an error when the file is missing, the URI is inaccessible, or the URI points to a directory.
SELECT *
FROM raw_audio
WHERE AUDIO_SIZE_FILTER(
audio_bytes,
NULL,
10485760
);