音频静音检测处理器,智能识别音频是否为完全静音
输入列名 | 说明 |
|---|---|
audio_inputs | 存放音频路径或二进制的列 |
存放静音检测结果的布尔值列,True表示静音,False表示非静音,None表示处理失败或没有声道
如参数没有默认值,则为必填参数
参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
silence_threshold_db | float | -60.0 | 静音音量阈值(dB),当音频最大音量低于此值时认为是静音 默认值:-60.0 (dB) |
timeout | int or None | None | 单个音频处理超时时间(秒),为None时不限制 默认值:None |
下面的代码展示了如何使用 Daft(适用于分布式)运行算子对音频进行静音检测。
from __future__ import annotations import os import daft from daft import col from daft.las.functions.audio import AudioSilenceDetection from daft.las.functions.udf import las_udf if __name__ == "__main__": TOS_TEST_DIR_URL = os.getenv("TOS_TEST_DIR_URL", "las-cn-beijing-public-online.tos-cn-beijing.volces.com") 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.context.set_runner_ray() daft.set_execution_config(actor_udf_ready_timeout=600) daft.set_execution_config(min_cpu_per_task=0) samples = { "input_path": [ f"https://{TOS_TEST_DIR_URL}/public/archive/audio_silence_detection/sample_silence.wav", f"https://{TOS_TEST_DIR_URL}/public/archive/audio_silence_detection/sample_speech.wav", ], } ds = daft.from_pydict(samples) # Using Daft to detect silence in audio files constructor_kwargs = { "silence_threshold_db": -60.0, "timeout": 30, } ds = ds.with_column( "is_silence", las_udf( AudioSilenceDetection, construct_args=constructor_kwargs, num_cpus=1, concurrency=1, batch_size=1, )(col("input_path")), ) ds.show() # ╭────────────────────────────────┬────────────╮ # │ input_path ┆ is_silence │ # │ --- ┆ --- │ # │ String ┆ Bool │ # ╞════════════════════════════════╪════════════╡ # │ https://las-public-data-qa.to… ┆ true │ # ├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌┤ # │ https://las-public-data-qa.to… ┆ false │ # ╰────────────────────────────────┴────────────╯