pyflink.multimodal.operators.audio_convert_format#
- audio_convert_format(*columns, format='wav', on_error='raise', max_decoded_bytes=1073741824, concurrency=None)[source]#
Convert encoded audio to another encoded format.
This is a boundary conversion for encoded inputs. It decodes the input and immediately re-encodes it to the requested format; it does not expose an intermediate
AUDIO_WAVEFORMcolumn.- Parameters
*columns – Optional audio columns. Supported inputs are
BYTESand URISTRING.format – Encoded output format. Common values are
"wav","flac","ogg","aiff", and"mp3". Actual availability depends on the worker’ssoundfile/libsndfile runtime. PyFlink writes a stable default subtype for each supported format; if the current libsndfile runtime does not support that subtype, the operator fails instead of silently choosing an environment-dependent subtype.on_error – Handling strategy for corrupt supported audio inputs.
"raise"propagates conversion failures."null"returnsNULLfor rows that cannot be decoded. URI access errors, encoding errors, and unsupported input kinds still raise.max_decoded_bytes – Maximum decoded PCM payload allowed during the decode-then-encode conversion. The default is 1 GiB.
concurrency – UDF concurrency.
Noneuses the framework default.
- Returns
A UDF producing encoded
BYTESin the requested format.- Raises
ValueError – If
on_erroris unsupported, the input is notBYTESor URISTRING, if the format is unsupported, or ifmax_decoded_bytesis invalid. Encoding errors, including an unavailable default output subtype, fail fast even whenon_error="null".
- Examples::
>>> # Usage 1: create a reusable UDF and apply it to a column. >>> convert = audio_convert_format( ... format="wav", ... on_error="null", ... max_decoded_bytes=1024 * 1024 * 1024, ... ) >>> df = df.with_column("wav", convert(col("uri"))) >>> >>> # Usage 2: pass the column directly when building the expression. >>> df = df.with_column( ... "wav", ... audio_convert_format( ... col("uri"), ... format="wav", ... on_error="null", ... max_decoded_bytes=1024 * 1024 * 1024, ... ), ... )