51 Commits
Author SHA1 Message Date
LauraGPT 9d611293f4 feat(audio): support explicit PCM16 input without container probing
Signed-off-by: LauraGPT <[email protected]>
2026-10-01 15:17:23 +00:00
li-lizhe ae5c4ccdec Remove hard torchaudio dependency for inference; add kaldi-native-fbank fbank backend (#3526)
* 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.
2026-08-27 00:23:11 +08:00
zhifu gao 763ee06e37 Decode container-formatted audio bytes before inference (#3435)
Decode encoded audio containers before inference while preserving the raw PCM fast path. Rewind file-like decoder fallbacks and support ffmpeg stdin decoding.

Signed-off-by: LauraGPT <[email protected]>
2026-07-27 14:55:49 +00:00
zhifu gaoandLauraGPT e6ab4c3704 fix(load): clear FileNotFoundError for missing audio path (#2981)
When an audio file path did not exist, load_audio_text_image_video silently
passed the raw string downstream, crashing later with a cryptic
"expected Tensor as element 1 in argument 0, but got str" deep inside the VAD.
New users following the README quickstart (placeholder meeting.wav) hit this
confusing internal error.

Now raise a clear FileNotFoundError naming the missing path. Scoped to
data_type=sound so text inputs are unaffected.

Tested: missing path -> FileNotFoundError with helpful message; valid path ->
unchanged.

Co-authored-by: LauraGPT <[email protected]>
2026-06-17 21:49:35 +08:00
游雁 80f3f2a4e9 fix: SenseVoice+spk_model crash and torchaudio>=2.11 compatibility
1. auto_model.py: When ASR model (e.g. SenseVoice) doesn't produce
   timestamps, automatically fall back to vad_segment mode for speaker
   diarization instead of crashing. Fixes #2945.

2. load_utils.py: Add soundfile as fallback when torchaudio.load fails
   (torchaudio>=2.11 requires torchcodec). Falls through to ffmpeg only
   if soundfile also fails.
2026-05-30 02:27:59 +08:00
游雁 78cc132a51 docs: add docstrings to 1950 functions across 276 files for API documentation 2026-05-21 07:52:52 +00:00
游雁 eeedd25881 docs: add docstrings to utility functions 2026-05-21 07:44:29 +00:00
Daniel BatesandYour Name a1bc5b5996 Fix #2793: convert stereo/multi-channel audio to mono in extract_fbank (#2819)
Co-authored-by: Your Name <[email protected]>
2026-02-27 20:57:46 +08:00
1045123a5c Fix #2787: model.generate时,传入的是音频字节流,会对采样率校验耗时200ms。 (#2820)
* Fix #2787: skip validate_frame_rate for raw PCM bytes in load_bytes

`validate_frame_rate` calls `pydub.AudioSegment.from_file` which takes
~200 ms.  When the caller passes raw PCM bytes (no container header) the
call always fails and the exception is silently swallowed, wasting 200 ms
on every invocation.

Add a lightweight `_is_audio_container` helper that inspects the first
few magic bytes of the input.  `load_bytes` now only calls
`validate_frame_rate` when the payload is a recognised container format
(WAV / MP3 / OGG / FLAC / MP4).  Raw PCM buffers skip the validation
entirely, eliminating the latency hit.

Also remove a stray `import pdb` debug statement.

* Apply suggestions from code review

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

---------

Co-authored-by: Your Name <[email protected]>
Co-authored-by: zhifu gao <[email protected]>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
2026-02-27 20:55:56 +08:00
weilikai eb1574b813 fix: support loading .pcm (16k 1c 16bit) audio files in load_utils.py (#2667) (#2668)
- Fix "Failed to load audio" error when recognizing .pcm audio files (16kHz, mono, 16bit)
- Ensure .pcm file support as described in issue #2667
2025-09-20 22:41:05 +08:00
天地andtiandiweizun e24dbdc496 感觉应该从文件读取更合适,因为上面判断了文件存在,且可以读取,如果本身是文本的话,下面也会有逻辑进行处理 (#2452)
Co-authored-by: tiandiweizun <[email protected]>
2025-03-26 13:44:41 +08:00
maliubiao 172a3152b4 允许 model.generate 使用bytes io, 以便不写入文件,节省io时间 (#2343) 2024-12-29 22:33:22 +08:00
游雁 1e5ef6ed9a bug fix 2024-12-23 19:06:50 +08:00
游雁 92586a4a90 fix bytes 2024-12-10 17:43:58 +08:00
游雁 4b3a28cbc5 pcm unfix 2024-11-28 15:53:17 +08:00
pointerhackerandzhaochaojin 37d6930561 fix:添加音频码率验证以防止模型异常 (#2219)
Co-authored-by: zhaochaojin <[email protected]>
2024-11-20 18:39:05 +08:00
游雁 a28de72b17 bugfix for paraformer-streaming 2024-08-02 01:55:30 +08:00
凪咲 85c1675e7c fix: fix input download logic (#1929) 2024-07-19 10:26:58 +08:00
zhifu gaoand维石 861147c730 Dev gzf exp (#1654)
* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* sensevoice finetune

* bugfix

* update with main (#1631)

* update seaco finetune

* v1.0.24

---------

Co-authored-by: 维石 <[email protected]>

* sensevoice

* sensevoice

* sensevoice

* update with main (#1638)

* update seaco finetune

* v1.0.24

* update rwkv template

---------

Co-authored-by: 维石 <[email protected]>

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sensevoice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* sense voice

* whisper

* whisper

* update style

* update style

---------

Co-authored-by: 维石 <[email protected]>
2024-04-24 16:03:38 +08:00
游雁 abf5af40e9 update 2024-03-26 15:07:45 +08:00
游雁 225e111c6d ffmpeg 2024-03-18 15:17:25 +08:00
游雁 27c7f88643 ffmpeg 2024-03-18 15:01:42 +08:00
游雁 ee4bf7fba4 ffmpeg 2024-03-18 15:01:17 +08:00
游雁 3d73f50beb ffmpeg 2024-03-18 14:51:16 +08:00
游雁 322f3d5ab9 ffmpeg 2024-03-18 14:43:36 +08:00
zhifu gao cae52c52f3 Revert "Revert "Dev yf" (#1418)" (#1420)
This reverts commit d2c1204d91.
2024-03-04 18:43:26 +08:00
zhifu gao d2c1204d91 Revert "Dev yf" (#1418) 2024-03-04 17:50:29 +08:00
语帆 1a6d9d5cc4 atsr 2024-03-04 16:32:28 +08:00
语帆 6d7b945710 atsr 2024-03-01 11:10:44 +08:00
语帆 d4955ba395 atsr 2024-03-01 10:42:37 +08:00
语帆 96eaabca5b atsr 2024-02-29 19:02:43 +08:00
语帆 84ad3e48a0 atsr 2024-02-29 18:58:08 +08:00
语帆 31e2eb39ad test 2024-02-28 16:14:57 +08:00
语帆 5b9c073f43 test 2024-02-28 15:49:41 +08:00
语帆 2bffe1d539 test 2024-02-28 14:52:05 +08:00
语帆 343a281ca1 test 2024-02-28 13:56:32 +08:00
语帆 5ecd13bd04 test 2024-02-28 11:23:51 +08:00
语帆 70a236b652 test 2024-02-23 17:38:54 +08:00
语帆 6a8c943435 test 2024-02-23 16:56:02 +08:00
65396eeeff vad streaming return [beg, -1], [], [-1, end], [beg, end] (#1306)
* fix add_file bug (#1296)

Co-authored-by: shixian.shi <[email protected]>

* funasr1.0 uniasr

* funasr1.0 uniasr

* update with main (#1305)

* v1.0.3

* update clients for 2pass

* update download tools

---------

Co-authored-by: 雾聪 <[email protected]>

* vad streaming return [beg, -1], [], [-1, end], [beg, end]]

---------

Co-authored-by: shixian.shi <[email protected]>
Co-authored-by: 雾聪 <[email protected]>
2024-01-26 11:26:48 +08:00
2c3183b611 Funasr1.0 (#1284)
* funasr1.0 update

* funasr1.0 paraformer-en

* update with main (#1281)

* Funasr1.0 (#1279)

* funasr1.0 update

* funasr1.0 paraformer-en

* update speaker infer

* update device

* update device

* update raw_text

* update infer

* update

* update infer

* bug fix

---------

Co-authored-by: shixian.shi <[email protected]>
Co-authored-by: Shi Xian <[email protected]>

* punc bugfix

* reduce_channels

---------

Co-authored-by: shixian.shi <[email protected]>
Co-authored-by: Shi Xian <[email protected]>
2024-01-23 11:16:34 +08:00
shixian.shi 1233c0d3ff code update 2024-01-15 20:34:47 +08:00
游雁 40d1f80030 funasr1.0 streaming demo 2024-01-12 12:05:08 +08:00
游雁 cf2f14345a funasr1.0 fsmn-vad streaming 2024-01-12 00:01:25 +08:00
游雁 a75bbb028e funasr1.0 paraformer_streaming 2024-01-11 17:36:30 +08:00
游雁 1028a8a036 funasr1.0 paraformer_streaming WavFrontendOnline 2024-01-10 17:42:53 +08:00
游雁 d8b586e02c funasr1.0 modelscope 2024-01-09 20:33:12 +08:00
游雁 f14f9f8d15 funasr1.0 infer url modelscope 2024-01-09 00:13:51 +08:00
游雁 e6a7bbe1ca load_audio_text_image_video 2024-01-05 17:00:11 +08:00
游雁 4f98546f36 load_audio_text_image_video 2024-01-05 16:55:07 +08:00