Audio properties and filtering

Updated at:

This topic describes the operators for audio validity checking, metadata, and filtering in the Python DataFrame API.

This topic describes the audio validity check, metadata, duration, duration filtering, and size filtering operators in the Python DataFrame API.

Limits

Operator list

Category

Operator

Description

Validity check

is_valid_audio

Determines whether an encoded audio object can be further processed by probing the media header or fully decoding it at the specified validation level, and returns a boolean result. Suitable for validating external audio ingestion, batch replay, or as an ASR pre-check. For example, you can first use metadata for lightweight filtering, and then use decode to rule out truncated audio, empty audio, and data whose decoded size exceeds the limit.

Property extraction

audio_metadata

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, you can choose a preprocessing pipeline based on sample rate, or identify abnormal data sources by format.

audio_duration

Returns the audio duration in seconds. Suitable for bucketing by audio length, estimating processing cost, or planning split strategies. For example, you can route overly long recordings to fixed-length splitting and send short recordings directly to ASR.

Filtering

audio_duration_filter

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, you can exclude invalid recordings shorter than 1 second, or block audio that exceeds the model input limit.

audio_size_filter

Checks the byte size of DataType.binary() or URI audio against a specified closed interval, without reading the media content. Suitable for controlling resource consumption before download, decoding, or downstream service calls. For example, you can filter out oversized objects up front to reduce network and memory pressure.

Common runtime parameters

Operator signatures retain the runtime parameters actually supported by each operator. To avoid repetition, operator parameter tables describe only business parameters. Runtime parameters are described below.

Parameter

Type

Default

Applies to

Description

concurrency

Optional[int]

None

All operators on this page

The UDF concurrency. None uses the framework default.

Validity check and property extraction

is_valid_audio

Validates whether encoded audio can be read. This operator does not accept decoded waveforms.

Input type: DataType.binary(), DataType.string(), or AUDIO_CLIP_REF_TYPE, an encoded audio bytes column, an audio URI column, or an audio segment reference column.

Signature:

is_valid_audio(
    *columns,
    validation="metadata",
    concurrency=None
)

Parameter

Type

Default

Description

validation

str

"metadata"

"metadata" probes only the container or file header. "decode" fully decodes the audio.

Returns False for null values, corrupted audio, truncated audio, unrecognized formats, and PCM data exceeding 1 GiB after full decoding. Exceptions are thrown for inaccessible URIs, invalid segment references, or missing dependencies.

Return type: DataType.boolean().

from pyflink.dataframe import col
from pyflink.multimodal.operators import is_valid_audio

result = df.filter(
    is_valid_audio(
        col("audio_bytes"),
        validation="metadata"
    )
)

audio_metadata

Reads metadata from encoded audio or a waveform.

Input type: DataType.binary(), DataType.string(), AUDIO_CLIP_REF_TYPE or AUDIO_WAVEFORM_TYPE, an encoded audio bytes column, an audio URI column, an audio segment reference column, or a decoded waveform column.

Signature:

audio_metadata(
    *columns,
    concurrency=None
)
  • Corrupt encoded audio returns None.

  • For an audio segment reference, frames and duration_ms are computed for the referenced interval, while size still reflects the size of the full encoded object.

  • For an audio waveform, format, codec, bit_rate, and size are None.

  • Inaccessible URIs, missing dependencies, unsupported input types, and internal errors still fail the job.

Return type: AUDIO_METADATA_TYPE.

from pyflink.multimodal.operators import audio_metadata

result = df.with_column(
    "audio_metadata",
    audio_metadata(col("audio_uri"))
)

audio_duration

Reads the audio duration.

Input type: DataType.binary(), DataType.string(), AUDIO_CLIP_REF_TYPE or AUDIO_WAVEFORM_TYPE, an encoded audio bytes column, an audio URI column, an audio segment reference column, or a decoded waveform column.

Signature:

audio_duration(
    *columns,
    concurrency=None
)

The return value is computed as duration_ms / 1000, in seconds. Returns None when the duration cannot be determined. Returns None when the encoded input is corrupt. An exception is thrown when the URI is inaccessible.

Return type: DataType.float64().

from pyflink.multimodal.operators import audio_duration

result = df.with_column(
    "duration_seconds",
    audio_duration(col("audio_bytes"))
)

audio_duration and audio_duration_filter use seconds. The duration_ms field in AUDIO_METADATA_TYPE and the time fields in audio segment references use milliseconds.

Filtering

audio_duration_filter

Checks whether the audio duration is within a specified closed interval.

Input type: DataType.binary(), DataType.string(), AUDIO_CLIP_REF_TYPE or AUDIO_WAVEFORM_TYPE, an encoded audio bytes column, an audio URI column, an audio segment reference column, or a decoded waveform column.

Signature:

audio_duration_filter(
    *columns,
    min_seconds=None,
    max_seconds=None,
    concurrency=None
)

Parameter

Type

Default

Description

min_seconds

Optional[float]

None

The minimum duration, in seconds. The bound is inclusive.

max_seconds

Optional[float]

None

The maximum duration, in seconds. The bound is inclusive.

At least one bound must be set. Bounds must be non-negative, and max_seconds >= min_seconds. Null inputs, inputs whose duration cannot be determined, and corrupt supported inputs return False.

Return type: DataType.boolean().

from pyflink.multimodal.operators import audio_duration_filter

result = df.filter(
    audio_duration_filter(
        col("audio_bytes"),
        min_seconds=0.5,
        max_seconds=600.0
    )
)

audio_size_filter

Checks whether the byte count of an encoded audio object is within a specified closed interval. This operator does not read or decode media content, so corrupt data whose size still matches the interval returns True.

Input type: DataType.binary() or DataType.string(), an encoded audio bytes column or an audio URI column. Audio segment references and waveforms are not supported.

Signature:

audio_size_filter(
    *columns,
    min_bytes=None,
    max_bytes=None,
    concurrency=None
)

Parameter

Type

Default

Description

min_bytes

Optional[int]

None

The minimum byte count. The bound is inclusive.

max_bytes

Optional[int]

None

The maximum byte count. The bound is inclusive.

At least one bound must be set. Null inputs return False. An exception is thrown if the URI does not exist, is inaccessible, or points to a directory.

Return type: DataType.boolean().

from pyflink.multimodal.operators import audio_size_filter

result = df.filter(
    audio_size_filter(
        col("audio_bytes"),
        min_bytes=1024,
        max_bytes=100 * 1024 * 1024
    )
)