本算子可用于语种识别、语言识别模块,是基于 Whisper 模型的多语言 LID(Language Identification**,**语言识别) + ASR (Automatic Speech Recognition,自动语音识别)解决方案。
en、zh)。openai/whisper-large-v3-turboopenai/whisper-large-v3openai/whisper-medium(中文支持一般)openai/whisper-small(中文输出可能为繁体)iic/punc_ct-transformer_cn-en-common-vocab471067-large支持中文、英文、德语、西班牙语等近百种语种,点击可查看完整语种列表。
输入列名 | 说明 |
|---|---|
audios | 包含音频数据的数组。每个元素可以是 |
一个结构化结果数组,其中每个元素为一个 struct,包含以下字段:
asr_result (str): 语音识别得到的文本结果。language (str): 识别出的语言代码(例如 en、zh)。asr_result_with_punc (Optional[str]): 可选的带标点化文本结果。当初始化时加载了标点模型且可用时返回,否则为 None。如参数没有默认值,则为必填参数。
参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
audio_src_type | str | 输入音频的来源类型,支持 | |
model_path | str |
| 模型根目录路径,通常包含若干模型子目录。 |
model_name | str |
| 模型名称,支持的 Whisper 系列模型包括: |
punc_model_name | Optional[str] |
| 可选的标点恢复模型名称,支持使用 |
return_language_only | bool |
| 是否仅返回语言识别结果而不进行语音转文本。若设置为 |
batch_size | int |
| 每次批处理的音频数量,值越大吞吐越高但显存/内存占用也越大。 |
device | str |
| 推理设备标识,例如 |
下面的代码展示了如何使用 daft 运行该算子进行语音的语种和文本识别。
from __future__ import annotations import logging import os import ray import daft from daft import col from daft.las.functions.audio.audio_asr_lid_whisper import AudioAsrLidWhisper from daft.las.functions.udf import las_udf if __name__ == "__main__": if os.getenv("DAFT_RUNNER", "ray") == "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) import ray 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) 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_normal.wav" ] } model_path = os.getenv("MODEL_PATH", "/opt/las/models") model_name = "openai/whisper-large-v3" audio_src_type = "audio_url" punc_model_name = "iic/punc_ct-transformer_cn-en-common-vocab471067-large" num_gpus = 1 device = "cuda" if num_gpus > 0 else "cpu" batch_size = 1 return_language_only = False df = daft.from_pydict(samples) df = df.with_column( "asr_result_detail", las_udf( AudioAsrLidWhisper, construct_args={ "audio_src_type": audio_src_type, "model_path": model_path, "model_name": model_name, "punc_model_name": punc_model_name, "return_language_only": return_language_only, "batch_size": batch_size, "device": device, }, num_gpus=num_gpus, batch_size=1, num_cpus=4, concurrency=1, )(col("audio_path")), ) df.show() # ╭───────────────────┬──────────────────────────────────────────╮ # │ audio_path ┆ asr_result_detail │ # │ --- ┆ --- │ # │ Utf8 ┆ Struct[asr_result: Utf8, language: Utf8, asr_result_with_punc: Utf8] │ # ╞═══════════════════╪══════════════════════════════════════════╡ # │ https://las-cn-beijing-publi-… ┆ {asr_result: 人我保住了金我取到了俺老孙啥功名… │ # ╰───────────────────┴──────────────────────────────────────────╯