Metadata-Version: 2.3
Name: fasr-asr-paraformer
Version: 0.5.8
Summary: paraformer asr model for fasr
Author: osc
Author-email: osc <790990241@qq.com>
Requires-Dist: fasr
Requires-Dist: funasr
Requires-Dist: torchaudio
Requires-Python: >=3.10, <3.13
Description-Content-Type: text/markdown

# fasr-asr-paraformer

英文文档地址: [README_EN.md](README_EN.md)

Paraformer 语音识别插件。离线模型返回带时间戳的 token，`seaco_paraformer` 额外支持热词偏置。

## 安装

```bash
pip install fasr-asr-paraformer
```

## 注册模型

| 注册名 | 类 | 适用场景 |
|---|---|---|
| `paraformer` | `Paraformer` | 离线 ASR，带 token 时间戳 |
| `seaco_paraformer` | `SeacoParaformer` | 离线 ASR，支持热词 |
| `paraformer_online` | `ParaformerOnline` | 流式 Paraformer ASR |

## 流水线使用

```python
from fasr import AudioPipeline

pipeline = (
    AudioPipeline()
    .add_pipe("detector", model="fsmn")
    .add_pipe(
        "recognizer",
        model="paraformer",
        batch_size=64,
        disable_log=True,
    )
    .add_pipe("sentencizer", model="ct_transformer")
)
```

热词识别使用 `seaco_paraformer`：

```python
pipeline = (
    AudioPipeline()
    .add_pipe("detector", model="fsmn")
    .add_pipe("recognizer", model="seaco_paraformer")
    .add_pipe("sentencizer", model="ct_transformer")
)

audio = pipeline.run("meeting.wav", hotwords=["Paraformer", "fasr"])[0]
```

## Confection 配置

```toml
[asr_model]
@asr_models = "paraformer"
batch_size = 64
device = "cuda:0"
disable_update = true
disable_log = true
disable_pbar = true
```

放在流水线里：

```toml
[pipeline]
@pipelines = "AudioPipeline.v1"
pipe_order = ["recognizer"]

[pipeline.pipes]

[pipeline.pipes.recognizer]
@pipes = "thread_pipe"
batch_size = 4

[pipeline.pipes.recognizer.component]
@components = "recognizer"

[pipeline.pipes.recognizer.component.model]
@asr_models = "paraformer"
batch_size = 64
device = "cuda:0"
disable_log = true
disable_pbar = true
```

## 单独使用

```python
from fasr.config import registry

model = registry.asr_models.get("paraformer")(batch_size=64)
spans = model.transcribe(audio_spans)
for span in spans:
    print(span.text)
    for token in span.tokens or []:
        print(token.text, token.start_ms, token.end_ms)
```

## 参数

| 参数 | 类型 / 范围 | 默认值 | 调高 / 开启时 | 调低 / 关闭时 | 什么时候改 |
|---|---|---|---|---|---|
| `batch_size` | `int >= 1` | `10000` | 吞吐更高，占用更多内存 | 内存更省，吞吐更低 | 批量太慢或内存太高 |
| `device` | `str \| null` | `null` | 显式指定设备，例如 `cuda:0` 或 `cpu` | 如果 CUDA 可用则自动选 `cuda:0`，否则选 `cpu` | 想覆盖自动设备选择时 |
| `disable_update` | `bool` | `True` | 跳过 FunASR 更新检查 | 允许检查更新 | 需要稳定启动或发现更新 |
| `disable_log` | `bool` | `True` | 隐藏后端日志 | 显示后端日志 | 调试加载或推理 |
| `disable_pbar` | `bool` | `True` | 隐藏进度条 | 显示进度条 | 交互式脚本需要进度 |
| `compile_model` | `bool`，仅 online | `False` | 使用 `torch.compile`，预热慢但稳态可能更快 | 无编译预热 | 长期运行流式服务 |
| `chunk_size_ms` | `int`，仅 online | `600` | 调用更少，输出更晚 | 更实时，调度更多 | 流式延迟/吞吐调优 |

## 输出

- `paraformer` 和 `seaco_paraformer` 会填充 `span.raw_text`。
- 有时间戳时，`span.tokens` 中的 `start_ms` / `end_ms` 是 channel 绝对时间。
- 如果不传 `device`，模型会在检测到 CUDA 时自动选 `cuda:0`，
  否则回退到 `cpu` 并给出提醒日志。
- `seaco_paraformer` 可通过 `hotwords=[...]` 传热词。

## 依赖

- `fasr`
- `funasr`
- Python 3.10-3.12
