This commit is contained in:
LauraGPT
2026-09-16 02:28:16 +00:00
parent 845e4ddc9e
commit a0bd3a13bc
+34 -27
View File
@@ -1002,9 +1002,12 @@
Falls back to CPU if specified device is unavailable.
vad_model (str, optional): VAD model for long audio segmentation.
Enables processing of any-length audio.
vad_kwargs (dict, optional): VAD config, e.g. {"max_single_segment_time": 60000}.
vad_kwargs (dict, optional): VAD config, e.g. {"device": "cpu"}.
Explicit device overrides the ASR device; otherwise inherits its resolved device.
punc_model (str, optional): Punctuation restoration model.
Not needed for Fun-ASR-Nano/SenseVoice/Qwen3-ASR (they output punctuation natively).
punc_kwargs (dict, optional): Punctuation config; device follows the same rules as vad_kwargs.
spk_kwargs (dict, optional): Speaker config; device follows the same rules as vad_kwargs.
spk_model (str, optional): Speaker model for diarization ("cam++" or full model ID).
Requires vad_model. For Qwen3-ASR, also requires forced_aligner.
spk_mode (str, optional): Speaker diarization mode. "punc_segment" (default) or "vad_segment".
@@ -1018,9 +1021,6 @@
>>> model = AutoModel(model="paraformer-zh", vad_model="fsmn-vad", punc_model="ct-punc")
>>> model = AutoModel(model="FunAudioLLM/Fun-ASR-Nano-2512", trust_remote_code=True,
... remote_code="./model.py", vad_model="fsmn-vad", spk_model="cam++", hub="hf")
"""
if "vda_model" in kwargs:
raise TypeError(
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L418" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details><h3 class="mt">Constructor</h3><div class="mblk"><a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L420">L420</a><p>Initialize AutoModel with ASR model and optional sub-models.</p>
<h4>Args:</h4>
<ul>
@@ -1029,9 +1029,12 @@
<li class="sub">Falls back to CPU if specified device is unavailable.</li>
<li><code>vad_model (str, optional)</code> — VAD model for long audio segmentation.</li>
<li class="sub">Enables processing of any-length audio.</li>
<li><code>vad_kwargs (dict, optional)</code> — VAD config, e.g. {"max_single_segment_time": 60000}.</li>
<li><code>vad_kwargs (dict, optional)</code> — VAD config, e.g. {"device": "cpu"}.</li>
<li class="sub">Explicit device overrides the ASR device; otherwise inherits its resolved device.</li>
<li><code>punc_model (str, optional)</code> — Punctuation restoration model.</li>
<li class="sub">Not needed for Fun-ASR-Nano/SenseVoice/Qwen3-ASR (they output punctuation natively).</li>
<li><code>punc_kwargs (dict, optional)</code> — Punctuation config; device follows the same rules as vad_kwargs.</li>
<li><code>spk_kwargs (dict, optional)</code> — Speaker config; device follows the same rules as vad_kwargs.</li>
<li><code>spk_model (str, optional)</code> — Speaker model for diarization ("cam++" or full model ID).</li>
<li class="sub">Requires vad_model. For Qwen3-ASR, also requires forced_aligner.</li>
<li><code>spk_mode (str, optional)</code> — Speaker diarization mode. "punc_segment" (default) or "vad_segment".</li>
@@ -1045,7 +1048,7 @@
<p>&gt;&gt;&gt; model = AutoModel(model="paraformer-zh", vad_model="fsmn-vad", punc_model="ct-punc")</p>
<p>&gt;&gt;&gt; model = AutoModel(model="FunAudioLLM/Fun-ASR-Nano-2512", trust_remote_code=True,</p>
<p>... remote_code="./model.py", vad_model="fsmn-vad", spk_model="cam++", hub="hf")</p>
</div><h3 class="mt">Methods</h3><div class="mblk"><code>.build_model(**kwargs)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L522" rel="noopener noreferrer" target="_blank">L522</a><div class="mdoc"><p>Download model from hub, build all components, and load pretrained weights.</p>
</div><h3 class="mt">Methods</h3><div class="mblk"><code>.build_model(**kwargs)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L529" rel="noopener noreferrer" target="_blank">L529</a><div class="mdoc"><p>Download model from hub, build all components, and load pretrained weights.</p>
<p>This method handles the full model construction pipeline:</p>
<p>1. Download model files from ModelScope/HuggingFace (if not local)</p>
<p>2. Parse config.yaml to determine model class, tokenizer, frontend</p>
@@ -1090,7 +1093,7 @@
kwargs.setdefault("model_conf", {})
kwargs.setdefault("model_path", kwargs["model"])
if "model_conf" not in kwargs:
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L522" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.generate(input, input_len=None, progress_callback=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L695" rel="noopener noreferrer" target="_blank">L695</a><div class="mdoc"><p>Run speech recognition on input audio.</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L529" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.generate(input, input_len=None, progress_callback=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L702" rel="noopener noreferrer" target="_blank">L702</a><div class="mdoc"><p>Run speech recognition on input audio.</p>
<p>This is the primary user-facing method. It automatically routes to:</p>
<ul>
<li>inference() if no vad_model is configured (single utterance)</li>
@@ -1107,6 +1110,8 @@
<li><code>input_len (tensor, optional)</code> — Length of each input sample.</li>
<li><code>progress_callback (callable, optional)</code> — fn(current, total) called during processing.</li>
<li><code>**cfg</code> — Runtime parameters:</li>
<li>device: Placement is selected at construction. Runtime device overrides</li>
<li class="sub">are ignored; create another AutoModel to use a different device.</li>
<li>cache (dict): State cache for streaming mode. Pass {} for first call.</li>
<li>hotword (str/list): Keywords to boost recognition accuracy.</li>
<li>postprocess_hotwords (str/list/dict): Text-level hotword correction after</li>
@@ -1147,6 +1152,8 @@
input_len (tensor, optional): Length of each input sample.
progress_callback (callable, optional): fn(current, total) called during processing.
**cfg: Runtime parameters:
- device: Placement is selected at construction. Runtime device overrides
are ignored; create another AutoModel to use a different device.
- cache (dict): State cache for streaming mode. Pass {} for first call.
- hotword (str/list): Keywords to boost recognition accuracy.
- postprocess_hotwords (str/list/dict): Text-level hotword correction after
@@ -1158,9 +1165,7 @@
- language (str): Language hint ("auto", "zh", "en", "Chinese", etc.)
- batch_size_s (int): Dynamic batch total duration in seconds.
- is_final (bool): Last chunk flag for streaming mode.
- return_spk_res (bool): Return speaker diarization results.
- sentence_timestamp (bool): Return sentence-level timestamps.
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L695" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.inference(input, input_len=None, model=None, kwargs=None, key=None, progress_callback=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L756" rel="noopener noreferrer" target="_blank">L756</a><div class="mdoc"><p>Run model inference on input data (internal method).</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L702" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.inference(input, input_len=None, model=None, kwargs=None, key=None, progress_callback=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L764" rel="noopener noreferrer" target="_blank">L764</a><div class="mdoc"><p>Run model inference on input data (internal method).</p>
<p>Handles batching, timing, and progress reporting. Called by generate()</p>
<p>and inference_with_vad(). Typically not called directly by users.</p>
<h4>Args:</h4>
@@ -1205,7 +1210,7 @@
if kwargs is None:
self._reset_runtime_configs()
kwargs = self.kwargs if kwargs is None else kwargs
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L756" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.inference_with_vad(input, input_len=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L858" rel="noopener noreferrer" target="_blank">L858</a><div class="mdoc"><p>Run ASR with VAD segmentation, punctuation, and optional speaker diarization.</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L764" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.inference_with_vad(input, input_len=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L866" rel="noopener noreferrer" target="_blank">L866</a><div class="mdoc"><p>Run ASR with VAD segmentation, punctuation, and optional speaker diarization.</p>
<p>Pipeline:</p>
<p>1. VAD: Segment audio into speech regions</p>
<p>2. ASR: Recognize each segment (sorted by length for efficient batching)</p>
@@ -1244,13 +1249,13 @@
cfg["return_time_stamps"] = True
kwargs = self.kwargs
# step.1: compute the vad model
deep_update(self.vad_kwargs, cfg)
beg_vad = time.time()
res = self.inference(
input, input_len=input_len, model=self.vad_model, kwargs=self.vad_kwargs, **cfg
)
end_vad = time.time()
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L858" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.export(input=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1263" rel="noopener noreferrer" target="_blank">L1263</a><div class="mdoc"><p>Export model to ONNX format.</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L866" rel="noopener noreferrer" target="_blank">View full source →</a></details></div><div class="mblk"><code>.export(input=None, **cfg)</code> <a class="gh-link" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1273" rel="noopener noreferrer" target="_blank">L1273</a><div class="mdoc"><p>Export model to ONNX format.</p>
<p>Creates a deep copy of the model to isolate ONNX operator monkey-patching,</p>
<p>then runs torch.onnx.export. The original model remains usable after export.</p>
<h4>Args:</h4>
@@ -1295,8 +1300,8 @@
device = cfg.get("device", "cpu")
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1263" rel="noopener noreferrer" target="_blank">View full source →</a></details></div></div>
<div class="api-detail" id="e4" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.build_model(**kwargs)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L522" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Download model from hub, build all components, and load pretrained weights.</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1273" rel="noopener noreferrer" target="_blank">View full source →</a></details></div></div>
<div class="api-detail" id="e4" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.build_model(**kwargs)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L529" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Download model from hub, build all components, and load pretrained weights.</p>
<p>This method handles the full model construction pipeline:</p>
<p>1. Download model files from ModelScope/HuggingFace (if not local)</p>
<p>2. Parse config.yaml to determine model class, tokenizer, frontend</p>
@@ -1341,8 +1346,8 @@
kwargs.setdefault("model_conf", {})
kwargs.setdefault("model_path", kwargs["model"])
if "model_conf" not in kwargs:
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L522" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e5" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.generate(input, input_len=None, progress_callback=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L695" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Run speech recognition on input audio.</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L529" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e5" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.generate(input, input_len=None, progress_callback=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L702" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Run speech recognition on input audio.</p>
<p>This is the primary user-facing method. It automatically routes to:</p>
<ul>
<li>inference() if no vad_model is configured (single utterance)</li>
@@ -1359,6 +1364,8 @@
<li><code>input_len (tensor, optional)</code> — Length of each input sample.</li>
<li><code>progress_callback (callable, optional)</code> — fn(current, total) called during processing.</li>
<li><code>**cfg</code> — Runtime parameters:</li>
<li>device: Placement is selected at construction. Runtime device overrides</li>
<li class="sub">are ignored; create another AutoModel to use a different device.</li>
<li>cache (dict): State cache for streaming mode. Pass {} for first call.</li>
<li>hotword (str/list): Keywords to boost recognition accuracy.</li>
<li>postprocess_hotwords (str/list/dict): Text-level hotword correction after</li>
@@ -1399,6 +1406,8 @@
input_len (tensor, optional): Length of each input sample.
progress_callback (callable, optional): fn(current, total) called during processing.
**cfg: Runtime parameters:
- device: Placement is selected at construction. Runtime device overrides
are ignored; create another AutoModel to use a different device.
- cache (dict): State cache for streaming mode. Pass {} for first call.
- hotword (str/list): Keywords to boost recognition accuracy.
- postprocess_hotwords (str/list/dict): Text-level hotword correction after
@@ -1410,10 +1419,8 @@
- language (str): Language hint ("auto", "zh", "en", "Chinese", etc.)
- batch_size_s (int): Dynamic batch total duration in seconds.
- is_final (bool): Last chunk flag for streaming mode.
- return_spk_res (bool): Return speaker diarization results.
- sentence_timestamp (bool): Return sentence-level timestamps.
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L695" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e6" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.inference(input, input_len=None, model=None, kwargs=None, key=None, progress_callback=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L756" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Run model inference on input data (internal method).</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L702" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e6" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.inference(input, input_len=None, model=None, kwargs=None, key=None, progress_callback=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L764" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Run model inference on input data (internal method).</p>
<p>Handles batching, timing, and progress reporting. Called by generate()</p>
<p>and inference_with_vad(). Typically not called directly by users.</p>
<h4>Args:</h4>
@@ -1458,8 +1465,8 @@
if kwargs is None:
self._reset_runtime_configs()
kwargs = self.kwargs if kwargs is None else kwargs
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L756" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e7" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.inference_with_vad(input, input_len=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L858" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Run ASR with VAD segmentation, punctuation, and optional speaker diarization.</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L764" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e7" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.inference_with_vad(input, input_len=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L866" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Run ASR with VAD segmentation, punctuation, and optional speaker diarization.</p>
<p>Pipeline:</p>
<p>1. VAD: Segment audio into speech regions</p>
<p>2. ASR: Recognize each segment (sorted by length for efficient batching)</p>
@@ -1498,14 +1505,14 @@
cfg["return_time_stamps"] = True
kwargs = self.kwargs
# step.1: compute the vad model
deep_update(self.vad_kwargs, cfg)
beg_vad = time.time()
res = self.inference(
input, input_len=input_len, model=self.vad_model, kwargs=self.vad_kwargs, **cfg
)
end_vad = time.time()
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L858" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e8" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.export(input=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1263" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Export model to ONNX format.</p>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L866" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e8" tabindex="-1"><span class="dtag badge-m">method</span><h2><code>AutoModel.export(input=None, **cfg)</code></h2><div class="dmod">funasr.auto.auto_model.AutoModel · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1273" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Export model to ONNX format.</p>
<p>Creates a deep copy of the model to isolate ONNX operator monkey-patching,</p>
<p>then runs torch.onnx.export. The original model remains usable after export.</p>
<h4>Args:</h4>
@@ -1550,7 +1557,7 @@
device = cfg.get("device", "cpu")
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1263" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
</code></pre><a class="src-more" href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model.py#L1273" rel="noopener noreferrer" target="_blank">View full source on GitHub →</a></details></div>
<div class="api-detail" id="e654" tabindex="-1"><span class="dtag badge-f">function</span><h2><code>check_vllm_applicable(model_name: str) -&gt; bool</code></h2><div class="dmod">funasr.auto.auto_model_vllm · <a href="https://github.com/modelscope/FunASR/blob/main/funasr/auto/auto_model_vllm.py#L68" rel="noopener noreferrer" target="_blank">View on GitHub ↗</a></div><div class="ddoc"><p>Check if a model can use vLLM inference.</p>
<h4>Args:</h4>
<ul>