Operator ID: daft.las.functions.audio.audio_concat.AudioConcat
Audio concatenation processor that supports concatenating multiple audio files into a single audio file.
Input column name | Description |
|---|---|
audio_paths_list | A column containing a list of audio file paths, where each element is a list of strings |
output_col | An array containing the output audio file paths |
An array containing the paths of the concatenated audio files. Returns the output path on success, or None on failure.
warning
If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
output_format | str | mp3 | Output audio format. Only "wav", "mp3", and "flac" are supported. The default is "mp3". |
sample_rate | int | 16000 | Output audio sample rate. The default is 16000. Caution: Since re-encoding is required when using the concat filter for concatenation, the sample rate is a required parameter. Common sample rates: 8000, 16000, 22050, 44100, 48000 |
timeout | int or None | None | ffmpeg execution timeout (seconds). The default is None (no timeout). |
extra_params | list or None | None | Additional ffmpeg parameter list, directly appended to the command. For example: - Bitrate: ["-b:a", "192k"] # for MP3 - Compression level: ["-compression_level", "8"] # for FLAC Default value: None |
The following code demonstrates how to use Daft (for distributed scenarios) to run the operator to concatenate multiple audio files.
from __future__ import annotations import os import daft from daft import col from daft.las.functions.audio import AudioConcat from daft.las.functions.udf import las_udf if __name__ == "__main__": # The converted audio will be saved to the specified TOS path. Therefore, you need to set the environment variables to ensure you have permission to write to TOS, including: ACCESS_KEY, SECRET_KEY, TOS_ENDPOINT, TOS_REGION, TOS_TEST_DIR TOS_TEST_DIR_URL = os.getenv("TOS_TEST_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") TOS_TEST_DIR = os.getenv("TOS_TEST_DIR", "tos_bucket") 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", ) 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) samples = { "audio_paths": [ [ f"https://{TOS_TEST_DIR_URL}/public/archive/audio_concat/sample_a.mp3", f"https://{TOS_TEST_DIR_URL}/public/archive/audio_concat/sample_b.wav", ], ], "output_path": [f"tos://{TOS_TEST_DIR}/audio_concat/output/concatenated_audio.mp3"], } ds = daft.from_pydict(samples) # Using Daft to concatenate audio files constructor_kwargs = { "output_format": "mp3", "sample_rate": 16000, "extra_params": ["-b:a", "192k"], } ds = ds.with_column( "output_path", las_udf( AudioConcat, construct_args=constructor_kwargs, num_cpus=1, concurrency=1, batch_size=1, )(col("audio_paths"), col("output_path")), ) ds.show() # ╭───────────────────┬────────────────────╮ # │ audio_paths ┆ output_path │ # │ --- ┆ --- │ # │ List[String] ┆ String │ # ╞═══════════════════╪════════════════════╡ # │ [https://las-public-data-qa.t… ┆ tos://tos_bucket/audio_concat… │ # ╰───────────────────┴──────────────────═─╯