Audio timestamp segmentation processor, supports precise segment extraction.
Input column names | Note |
|---|---|
timestamp_ranges | Required. Column containing timestamp intervals for splitting. |
audio_paths | Optional. Column containing audio file paths. |
audio_binaries | Optional. Column containing audio binary data. |
audio_formats | Optional. Column containing audio format strings. This column must be specified when audio_binaries is provided. |
output_basenames | Optional. Column containing specified file names. |
A struct containing the audio segmentation results:
If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
output_tos_dir | str | The path in TOS where the split audio segments are saved. | |
output_segments_binary | bool | False | Whether to return the binary data of the split audio segments. |
output_format | str or None | Globally specify the output audio format (such as "mp3", "wav", and so on). This takes precedence over the input file extension and the audio_format column. |
The following code demonstrates how to use Daft (for distributed processing) to run the operator and split audio by timestamps.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.audio import AudioSplitByTimestamps from daft.las.functions.udf import las_udf if __name__ == "__main__": # After splitting, the audio will be saved to the specified TOS path. Therefore, you need to set environment variables to ensure you have permission to write to TOS, including: ACCESS_KEY, SECRET_KEY, TOS_ENDPOINT, TOS_REGION, TOS_TEST_DIR TOS_DIR = os.getenv("TOS_TEST_DIR", "tos_bucket") output_tos_dir = f"tos://{TOS_DIR}/audio/audio_split_by_timestamps" if os.getenv("DAFT_RUNNER", "native") == "ray": import logging import ray def configure_logging(): logging.basicConfig( level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S.%s".format(), ) logging.getLogger("tracing.span").setLevel(logging.WARNING) logging.getLogger("daft_io.stats").setLevel(logging.WARNING) logging.getLogger("DaftStatisticsManager").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaScheduler").setLevel(logging.WARNING) logging.getLogger("DaftFlotillaDispatcher").setLevel(logging.WARNING) ray.init(dashboard_host="0.0.0.0", runtime_env={"worker_process_setup_hook": configure_logging}) daft.set_runner_ray() daft.set_execution_config(actor_udf_ready_timeout=600) daft.set_execution_config(min_cpu_per_task=0) # Build the URL using environment variables tos_dir_url = os.getenv("TOS_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") samples = { "audio_path": [ f"https://{tos_dir_url}/public/shared_audio_dataset/sample.mp3" ], "timestamps": [[(0.0, 5.0), (5.0, 10.0), (10.0, 15.0)]], } ds = daft.from_pydict(samples) constructor_kwargs = { "output_tos_dir": output_tos_dir, "output_segments_binary": True, "output_audio_format": True, } # Use Daft for distributed processing ds = ds.with_column( "split_results", las_udf(AudioSplitByTimestamps, construct_args=constructor_kwargs)(col("timestamps"), col("audio_path")), ) ds.show() # ╭────────────────────────────────┬─────────────────────────────┬───────────────────────────────────────────────────────────────────────────╮ # │ audio_path ┆ timestamps ┆ split_results │ # │ --- ┆ --- ┆ --- │ # │ Utf8 ┆ List[List[Float64]] ┆ Struct[segments: List[Utf8], binaries: List[Binary], formats: List[Utf8]] │ # ╞════════════════════════════════╪═════════════════════════════╪═══════════════════════════════════════════════════════════════════════════╡ # │ https://las-cn-beijing-publi-… ┆ [[0, 5], [5, 10], [10, 15]] ┆ {segments: ["tos://tos_bucket/audio/audio_split_by_timestamps/segment_1.… │ # ╰────────────────────────────────┴─────────────────────────────┴───────────────────────────────────────────────────────────────────────────╯