module pixeltable.functions.audio
Pixeltable UDFs forAudioType.
iterator audio_splitter()
Signature
duration (seconds) or by max_size (bytes). Exactly one of the two must be specified.
- With
max_size, every emitted segment is guaranteed not to exceed the given number of bytes. - With
duration, each segment is approximately that long (a segment may run over by up to one packet).
segment_start(pxt.Float): Start time of the audio segment in secondssegment_end(pxt.Float): End time of the audio segment in secondsaudio_segment(pxt.Audio | None): The audio content of the segment
min_silence_len is set, segment boundaries are snapped to silences so that segments do not end in the
middle of speech: each segment ends at the latest silence at or before its duration or max_size budget.
trim_leading_silence additionally drops silence from the start of every segment.
Parameters:
duration(pxt.Float | None): Audio segment duration in seconds. Mutually exclusive withmax_size.max_size(pxt.Int | None): Maximum audio segment size in bytes. Mutually exclusive withduration.overlap(pxt.Float): Overlap between consecutive segments in secondsmin_segment_duration(pxt.Float): Drop the last segment if it is smaller thanmin_segment_duration(in seconds).min_silence_len(pxt.Float | None): If set, enables silence-aware boundaries; the minimum length in seconds of a quiet stretch that counts as a usable cut point.silence_thresh(pxt.Float): Level in dBFS at or below which audio is considered silent. Used whenmin_silence_lenis set ortrim_leading_silenceis true.trim_leading_silence(pxt.Bool): If true, drop leading silence from each segment so it starts at audible content.
tbl with a column audio of type pxt.Audio.
Create a view that splits all audio files into segments of 30 seconds with 5 seconds overlap:
udf encode_audio()
Signature
audio_data(pxt.Array[float32]): An array of sampled amplitudes. The accepted array shapes are(N,)or(1, N)for mono audio or(2, N)for stereo.input_sample_rate(pxt.Int): The sample rate of the input audio data.format(pxt.String): The desired output audio format. The supported formats are ‘wav’, ‘mp3’, ‘flac’, and ‘mp4’.output_sample_rate(pxt.Int | None): The desired sample rate for the output audio. Defaults to the input sample rate if unspecified.
udf get_metadata()
Signature
ContainerMetadata dictionary.
Parameters:
audio(pxt.Audio): The audio to get metadata for.
ContainerMetadata: AContainerMetadatawith typical structure:
audio_col column of the table tbl: