Metadata-Version: 2.4
Name: fasr-asr-funasr
Version: 0.5.7
Summary: Fun ASR model for fasr
Author-email: fasr <wangmengdi06@58.com>
Requires-Python: <3.13,>=3.10
Description-Content-Type: text/markdown
Requires-Dist: fasr
Requires-Dist: funasr

# fasr-asr-funasr

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

Fun-ASR-Nano 语音识别插件。该插件封装 `funasr.AutoModel`，把整段识别文本写入
`AudioSpan.raw_text`，不返回词级或字级时间戳。

## 安装

```bash
pip install fasr-asr-funasr
```

## 注册模型

| 注册名 | 类 | 适用场景 |
|---|---|---|
| `fun_asr_nano` | `FunASRNano` | 轻量 FunASR 识别，无时间戳输出 |

默认 checkpoint 是 `FunAudioLLM/Fun-ASR-Nano-2512`。

## 流水线使用

```python
from fasr import AudioPipeline

pipeline = (
    AudioPipeline()
    .add_pipe("detector", model="fsmn")
    .add_pipe(
        "recognizer",
        model="fun_asr_nano",
        device="cuda:0",
        language="中文",
        itn=True,
    )
    .add_pipe("sentencizer", model="ct_transformer")
)
```

| 目标 | 写法 | 效果 |
|---|---|---|
| CPU 推理 | `device="cpu"` | 不依赖 CUDA，但通常更慢 |
| 使用第一张 GPU | `device="cuda:0"` | 使用 GPU 0 |
| 关闭数字/日期规范化 | `itn=False` | 保留更接近口语的文本 |
| 固定语言提示 | `language="中文"` | 把语言标签传给 FunASR |

## Confection 配置

```toml
[asr_model]
@asr_models = "fun_asr_nano"
device = "cuda:0"
language = "中文"
itn = true
batch_size = 1
```

放在流水线里：

```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 = "fun_asr_nano"
device = "cuda:0"
language = "中文"
itn = true
batch_size = 1
```

## 单独使用

```python
from fasr.config import registry

model = registry.asr_models.get("fun_asr_nano")()
model.device = "cuda:0"

spans = model.transcribe(audio_spans, hotwords=["fasr"], language="中文")
for span in spans:
    print(span.text)
```

使用本地权重：

```python
model.load_checkpoint("/path/to/Fun-ASR-Nano")
```

## 参数

| 参数 | 类型 / 范围 | 默认值 | 调高 / 开启时 | 调低 / 关闭时 | 什么时候改 |
|---|---|---|---|---|---|
| `device` | `str` | `"cuda:0"` | 选择 CUDA 设备，如 `"cuda:1"` | `"cpu"` 使用 CPU | 部署设备变化 |
| `language` | `str` | `"中文"` | 更强语言提示 | 换成其它支持的语言标签 | 已知音频语言 |
| `itn` | `bool` | `True` | 规范化数字、日期等 | 保留较原始文本 | 需要口语形式输出 |
| `batch_size` | `int >= 1` | `1` | 吞吐更高，占用更多内存 | 内存更省，吞吐更低 | 批量推理调优 |
| `trust_remote_code` | `bool` | `True` | 允许加载 checkpoint 自定义代码 | 更安全，但部分模型可能加载失败 | 使用不可信 checkpoint |

## 输出

- 写入 `span.raw_text`。
- 不填充 `span.tokens`，因为 Fun-ASR-Nano 不返回时间戳。
- 读取 `span.text` 即可得到识别文本。

## 依赖

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