funasr_onnx streaming Paraformer returns inconsistent structures for empty results

已关闭 适合新手
#3,791 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@ychy7001 已经在做这个了。

开始于 2026年10月24日。

  • #3792 来自 @ychy7001 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
68/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
api

调研方向

阅读 funasr_onnx/paraformer_online_bin.py,尤其是第 172-186 行附近将结果合并到 res = {} 的最终调用分块逻辑,并比较非最终 infer 路径和单 chunk 最终路径的空结果返回。该 issue 已经附带了使用静音输入和 chunk_size=[5, 10, 5] 的复现脚本;运行它以查看所有三种返回结构。注意,确切的返回契约尚未得到维护者确认(issue 中已提出),因此在提交带有回归测试的 PR 之前,先发评论确认目标结构([])是安全完成任务的路径。

由索引模型根据 Issue 内容生成。

描述

Description

funasr_onnx.paraformer_online_bin.Paraformer.__call__ returns different structures when there is no recognition result, depending on which path is taken:

case return value
non-final call, no tokens (infer → asr_res = []) []
final call handled as one chunk, decoder runs but text is empty [{'preds': ['', []]}]
final call split into two chunks, neither chunk has a result (lines 172-186 merge into res = {}) [{}]

The last case means callers that read res[0]["preds"] after checking if res: hit KeyError: 'preds'; they have to check for an empty dict as well.

Reproduction

main (fbbfe01), iic/speech_paraformer-large_asr_nat-zh-cn-16k-common-vocab8404-online v2.0.5 exported to ONNX, onnxruntime 1.20.1, CPU. Silence is enough to trigger it; chunk_size=[5, 10, 5] (the package default) is used, so this is unrelated to #3789.

import numpy as np
from funasr_onnx.paraformer_online_bin import Paraformer

model = Paraformer(model_dir, batch_size=1, chunk_size=[5, 10, 5], quantize=False)
for n_final in (9600, 16000):
    cache = {}
    r1 = model(np.zeros(9600, np.float32), param_dict={"cache": cache, "is_final": False})
    r2 = model(np.zeros(n_final, np.float32), param_dict={"cache": cache, "is_final": True})
    print(n_final, r1, r2)

Output:

9600 [] [{'preds': ['', []]}]
16000 [] [{}]

Question

What is the intended return value when there is no result? Returning [] in the split-final path, consistent with the non-final path, looks simplest, but I am not sure whether existing callers rely on [{}] or on [{'preds': ['', []]}]. If you confirm the expected contract, I can send a small PR with a regression test.

主要语言
Python
星标
20.9k
派生
2.1k
平均合并
1 天 3 小时
30 天内合并 PR
46

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelscope/FunASR 的其他 Issue

查看 modelscope/FunASR 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。