This operator can be used for language identification modules. It is a multilingual LID (Language Identification**,** language identification) + ASR (Automatic Speech Recognition, automatic speech recognition) solution based on the Whisper model.
en, zh).openai/whisper-large-v3-turboopenai/whisper-large-v3openai/whisper-medium (Chinese support is limited)openai/whisper-small (may output traditional Chinese characters)iic/punc_ct-transformer_cn-en-common-vocab471067-largeSupports nearly one hundred languages including Chinese, English, German, Spanish, and more. See the complete language list.
Input column name | Note |
|---|---|
audios | An array containing audio data. Each element can be |
A structured result array, where each element is a struct containing the following fields:
asr_result (str): The text result obtained from speech recognition.language (str): The recognized language code (for example, en, zh).asr_result_with_punc (Optional[str]): Optional text result with punctuation. Returned when the punctuation model is loaded and available during initialization; otherwise, None.If a parameter does not have a default value, it is required.
Parameter name | Type | Default value | Description |
|---|---|---|---|
audio_src_type | str | Type of input audio source. Supports | |
model_path | str |
| Root directory path for models, typically containing several model subdirectories. |
model_name | str |
| Model name. Supported Whisper series models include: |
punc_model_name | Optional[str] |
| Optional punctuation restoration model name. Supports using |
return_language_only | bool |
| Whether to return only the language recognition result without performing speech-to-text conversion. If set to |
batch_size | int |
| Number of audio files processed per batch. Higher values increase throughput but also increase GPU/memory usage. |
device | str |
| Inference device identifier, such as "cpu", "cuda", or "cuda:0". The default is "cpu". |
The following code demonstrates how to use daft to run this operator for speech language identification and transcription.
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: 人我保住了金我取到了俺老孙啥功名… │ # ╰───────────────────┴──────────────────────────────────────────╯