mirror of
https://github.com/modelscope/FunASR.git
synced 2026-10-12 02:19:18 +00:00
* Remove hard torchaudio dependency for inference; add kaldi-native-fbank fbank backend Make torchaudio an optional dependency for the inference path so FunASR can run on Ascend NPU (aarch64) servers, where no matching torchaudio wheel exists (Huawei's Ascend torch is version-decoupled from the PyTorch upstream release line). - Add funasr/utils/fbank.py: an fbank shim that delegates to torchaudio.compliance.kaldi when torchaudio is installed, otherwise falls back to kaldi-native-fbank (a torch-free C++ library with aarch64 wheels). Options and frame-shift API are mapped to torchaudio semantics so outputs are equivalent. - Switch funasr/frontends/wav_frontend.py, funasr/utils/speaker_utils.py and funasr/models/campplus/utils.py to the shim. - Make the torchaudio import optional in funasr/utils/load_utils.py (resampler falls back to librosa). No device-specific branching is introduced — a pure backend fallback that also benefits CPU-only and other accelerator platforms. Verified end-to-end on Ascend 910B (npu:0) with torchaudio absent: paraformer-large loads and infers correctly, RTF ~0.016 (~60x realtime). * Make torchaudio import optional in paraformer_v2, fun_asr_nano and dataset preprocessors Follow-up to the inference-path change: make the remaining top-level torchaudio imports optional so these modules import cleanly when torchaudio is not installed (e.g. on Ascend NPU servers). - funasr/models/paraformer_v2_community/model.py - funasr/models/fun_asr_nano/tools/utils.py - funasr/datasets/audio_datasets/preprocessor.py - funasr/datasets/llm_datasets/preprocessor.py Functions that still require torchaudio (forced_align, Resample) degrade to a clear error only when called, rather than a hard import failure. * Address review: declare knf extra, harden fbank fallback and torchaudio guards Respond to maintainer review feedback. - Declare kaldi-native-fbank as an optional 'knf' extra in setup.py; the fbank module now raises an actionable ImportError only when fbank() is actually called with neither torchaudio nor kaldi-native-fbank installed (previously it failed at import time with a bare ModuleNotFoundError). - Harden the fbank fallback contract: handle the channel argument explicitly and reject torchaudio-only options (subtract_mean, min_duration, VTLN warping, non-default blackman_coeff) with NotImplementedError instead of silently dropping them via **kwargs. - Add a shared guard funasr/utils/torchaudio_compat.py and use it for resampling, forced alignment and speed perturbation so a missing torchaudio fails loudly instead of returning a silently wrong result (empty alignment). - Add regression tests (tests/test_torchaudio_optional.py) that import the affected modules with torchaudio absent.
202 lines
6.4 KiB
Python
202 lines
6.4 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""FunASR setup script."""
|
|
|
|
import os
|
|
|
|
from setuptools import find_packages
|
|
from setuptools import setup
|
|
|
|
|
|
requirements = {
|
|
"install": [
|
|
# Core
|
|
"scipy>=1.4.1",
|
|
"librosa",
|
|
"soundfile>=0.12.1",
|
|
"numpy",
|
|
"PyYAML>=5.1.2",
|
|
"tqdm",
|
|
"requests",
|
|
"regex",
|
|
"websockets>=10.4",
|
|
# Model loading
|
|
"omegaconf>=2.0",
|
|
"hydra-core>=1.3.2",
|
|
"modelscope",
|
|
"huggingface_hub",
|
|
"safetensors",
|
|
# ASR models
|
|
"transformers",
|
|
"tiktoken",
|
|
"sentencepiece",
|
|
"kaldiio>=2.17.0",
|
|
# Multilingual tokenizers
|
|
"jieba",
|
|
"jamo",
|
|
"jaconv",
|
|
# Speaker & evaluation
|
|
"umap_learn",
|
|
"rapidfuzz>=3.0.0",
|
|
# Optional (training/enhancement)
|
|
"torch_complex",
|
|
"tensorboardX",
|
|
# PAI/Aliyun
|
|
"oss2",
|
|
],
|
|
# knf: kaldi-native-fbank fallback backend used when torchaudio is absent
|
|
# (e.g. Ascend NPU / aarch64 servers with no matching torchaudio wheel).
|
|
"knf": [
|
|
"kaldi-native-fbank",
|
|
],
|
|
# train: The modules invoked when training only.
|
|
"train": [
|
|
"rapidfuzz>=3.0.0",
|
|
],
|
|
"silero": [
|
|
"silero-vad>=6.0.0",
|
|
],
|
|
# all: The modules should be optionally installled due to some reason.
|
|
# Please consider moving them to "install" occasionally
|
|
"all": [
|
|
# NOTE(kamo): Append modules requiring specific pytorch version or torch>1.3.0
|
|
"torch_optimizer",
|
|
"fairscale",
|
|
"transformers",
|
|
"openai-whisper",
|
|
],
|
|
"setup": [
|
|
"numpy",
|
|
"pytest-runner",
|
|
],
|
|
"test": [
|
|
"pytest>=3.3.0",
|
|
"pytest-timeouts>=1.2.1",
|
|
"pytest-pythonpath>=0.7.3",
|
|
"pytest-cov>=2.7.1",
|
|
"hacking>=2.0.0",
|
|
"mock>=2.0.0",
|
|
"pycodestyle",
|
|
"jsondiff<2.0.0,>=1.2.0",
|
|
"flake8>=3.7.8",
|
|
"flake8-docstrings>=1.3.1",
|
|
"black",
|
|
],
|
|
"doc": [
|
|
"Jinja2",
|
|
"Sphinx",
|
|
"sphinx-rtd-theme>=0.2.4",
|
|
"sphinx-argparse>=0.2.5",
|
|
"commonmark",
|
|
"recommonmark>=0.4.0",
|
|
"nbsphinx>=0.4.2",
|
|
"sphinx-markdown-tables>=0.0.12",
|
|
"configargparse>=1.2.1",
|
|
],
|
|
"llm": [
|
|
"transformers>=4.32.0",
|
|
"accelerate",
|
|
"tiktoken",
|
|
"einops",
|
|
"transformers_stream_generator>=0.0.4",
|
|
"scipy",
|
|
"torchvision",
|
|
"pillow",
|
|
"matplotlib",
|
|
],
|
|
}
|
|
requirements["all"].extend(requirements["train"])
|
|
requirements["all"].extend(requirements["llm"])
|
|
requirements["test"].extend(requirements["train"])
|
|
|
|
install_requires = requirements["install"]
|
|
setup_requires = requirements["setup"]
|
|
tests_require = requirements["test"]
|
|
extras_require = {k: v for k, v in requirements.items() if k not in ["install", "setup"]}
|
|
|
|
dirname = os.path.dirname(__file__)
|
|
version_file = os.path.join(dirname, "funasr", "version.txt")
|
|
with open(version_file, "r") as f:
|
|
version = f.read().strip()
|
|
setup(
|
|
name="funasr",
|
|
version=version,
|
|
url="https://github.com/modelscope/FunASR",
|
|
author="Speech Lab of Alibaba Group",
|
|
author_email="[email protected]",
|
|
description="OpenAI-compatible speech recognition toolkit with WebSocket streaming, vLLM acceleration, and llama.cpp/GGUF edge runtime.",
|
|
keywords=[
|
|
"speech-recognition",
|
|
"asr",
|
|
"speaker-diarization",
|
|
"vad",
|
|
"pytorch",
|
|
"whisper-alternative",
|
|
"multilingual",
|
|
"openai-compatible",
|
|
"websocket",
|
|
"vllm",
|
|
"gguf",
|
|
"llama-cpp",
|
|
],
|
|
project_urls={
|
|
"Homepage": "https://github.com/modelscope/FunASR",
|
|
"Documentation": "https://modelscope.github.io/FunASR/",
|
|
"Bug Tracker": "https://github.com/modelscope/FunASR/issues",
|
|
},
|
|
long_description=open(os.path.join(dirname, "README.md"), encoding="utf-8").read(),
|
|
long_description_content_type="text/markdown",
|
|
license="The MIT License",
|
|
packages=find_packages(include=["funasr*"]),
|
|
package_data={
|
|
"funasr": [
|
|
"version.txt",
|
|
"models/sense_voice/whisper_lib/normalizers/english.json",
|
|
"models/rwkv_bat/cuda_encoder/*.cpp",
|
|
"models/rwkv_bat/cuda_encoder/*.cu",
|
|
"models/rwkv_bat/cuda_decoder/*.cpp",
|
|
"models/rwkv_bat/cuda_decoder/*.cu",
|
|
]
|
|
},
|
|
install_requires=install_requires,
|
|
setup_requires=setup_requires,
|
|
tests_require=tests_require,
|
|
extras_require=extras_require,
|
|
python_requires=">=3.7.0",
|
|
classifiers=[
|
|
"Programming Language :: Python",
|
|
"Programming Language :: Python :: 3",
|
|
"Programming Language :: Python :: 3.8",
|
|
"Programming Language :: Python :: 3.9",
|
|
"Programming Language :: Python :: 3.10",
|
|
"Programming Language :: Python :: 3.11",
|
|
"Programming Language :: Python :: 3.12",
|
|
"Development Status :: 5 - Production/Stable",
|
|
"Intended Audience :: Science/Research",
|
|
"Intended Audience :: Developers",
|
|
"Operating System :: POSIX :: Linux",
|
|
"Operating System :: MacOS",
|
|
"Operating System :: Microsoft :: Windows",
|
|
"License :: OSI Approved :: MIT License",
|
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
"Topic :: Multimedia :: Sound/Audio :: Speech",
|
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
],
|
|
entry_points={
|
|
"console_scripts": [
|
|
"funasr = funasr.cli:main",
|
|
"funasr-hydra = funasr.bin.inference:main_hydra",
|
|
"funasr-server = funasr.bin.server:main",
|
|
"funasr-realtime-server = funasr.bin.realtime_ws:cli_main",
|
|
"funasr-train = funasr.bin.train:main_hydra",
|
|
"funasr-train-ds = funasr.bin.train_ds:main_hydra",
|
|
"funasr-export = funasr.bin.export:main_hydra",
|
|
"scp2jsonl = funasr.datasets.audio_datasets.scp2jsonl:main_hydra",
|
|
"jsonl2scp = funasr.datasets.audio_datasets.jsonl2scp:main_hydra",
|
|
"sensevoice2jsonl = funasr.datasets.audio_datasets.sensevoice2jsonl:main_hydra",
|
|
"funasr-scp2jsonl = funasr.datasets.audio_datasets.scp2jsonl:main_hydra",
|
|
"funasr-jsonl2scp = funasr.datasets.audio_datasets.jsonl2scp:main_hydra",
|
|
"funasr-sensevoice2jsonl = funasr.datasets.audio_datasets.sensevoice2jsonl:main_hydra",
|
|
]
|
|
},
|
|
) |