@@ -73,7 +79,7 @@ SenseVoice是具有音频理解能力的音频基础模型,包括语音识别
## 事件检测
-尽管SenseVoice只在语音数据上进行训练,它仍然可以作为事件检测模型进行单独使用。我们在环境音分类ESC-50数据集上与目前业内广泛使用的BEATS与PANN模型的效果进行了对比。SenseVoice模型能够在这些任务上取得较好的效果,但受限于训练数据与训练方式,其事件分类效果专业的事件检测模型相比仍然有一定的差距。
+尽管 SenseVoice 只在语音数据上进行训练,它仍然可以作为事件检测模型进行单独使用。我们在环境音分类 ESC-50 数据集上与目前业内广泛使用的 BEATS 与 PANN 模型的效果进行了对比。SenseVoice 模型能够在这些任务上取得较好的效果,但受限于训练数据与训练方式,其事件分类效果专业的事件检测模型相比仍然有一定的差距。

@@ -81,13 +87,14 @@ SenseVoice是具有音频理解能力的音频基础模型,包括语音识别
## 推理效率
-SenseVoice-small模型采用非自回归端到端架构,推理延迟极低。在参数量与Whisper-Small模型相当的情况下,比Whisper-Small模型推理速度快5倍,比Whisper-Large模型快15倍。同时SenseVoice-small模型在音频时长增加的情况下,推理耗时也无明显增加。
+SenseVoice-small 模型采用非自回归端到端架构,推理延迟极低。在参数量与 Whisper-Small 模型相当的情况下,比 Whisper-Small 模型推理速度快 5 倍,比 Whisper-Large 模型快 15 倍。同时 SenseVoice-small 模型在音频时长增加的情况下,推理耗时也无明显增加。
+
# 安装依赖环境 🐍
```shell
@@ -95,13 +102,12 @@ pip install -r requirements.txt
```
+
# 用法 🛠️
## 推理
-
-
-### 使用funasr推理
+### 使用 funasr 推理
支持任意格式音频输入,支持任意时长输入
@@ -112,7 +118,7 @@ from funasr.utils.postprocess_utils import rich_transcription_postprocess
model_dir = "iic/SenseVoiceSmall"
-model = AutoModel(
+model = AutoModel (
model=model_dir,
trust_remote_code=True,
remote_code="./model.py",
@@ -122,7 +128,7 @@ model = AutoModel(
)
# en
-res = model.generate(
+res = model.generate (
input=f"{model.model_path}/example/en.mp3",
cache={},
language="auto", # "zh", "en", "yue", "ja", "ko", "nospeech"
@@ -131,29 +137,31 @@ res = model.generate(
merge_vad=True, #
merge_length_s=15,
)
-text = rich_transcription_postprocess(res[0]["text"])
-print(text)
+text = rich_transcription_postprocess (res [0]["text"])
+print (text)
```
-
参数说明(点击展开)
+
+ 参数说明(点击展开)
- `model_dir`:模型名称,或本地磁盘中的模型路径。
- `trust_remote_code`:
- - `True`表示model代码实现从`remote_code`处加载,`remote_code`指定`model`具体代码的位置(例如,当前目录下的`model.py`),支持绝对路径与相对路径,以及网络url。
- - `False`表示,model代码实现为 [FunASR](https://github.com/modelscope/FunASR) 内部集成版本,此时修改当前目录下的`model.py`不会生效,因为加载的是funasr内部版本,模型代码[点击查看](https://github.com/modelscope/FunASR/tree/main/funasr/models/sense_voice)。
-- `vad_model`:表示开启VAD,VAD的作用是将长音频切割成短音频,此时推理耗时包括了VAD与SenseVoice总耗时,为链路耗时,如果需要单独测试SenseVoice模型耗时,可以关闭VAD模型。
-- `vad_kwargs`:表示VAD模型配置,`max_single_segment_time`: 表示`vad_model`最大切割音频时长, 单位是毫秒ms。
+ - `True` 表示 model 代码实现从 `remote_code` 处加载,`remote_code` 指定 `model` 具体代码的位置(例如,当前目录下的 `model.py`),支持绝对路径与相对路径,以及网络 url。
+ - `False` 表示,model 代码实现为 [FunASR](https://github.com/modelscope/FunASR) 内部集成版本,此时修改当前目录下的 `model.py` 不会生效,因为加载的是 funasr 内部版本,模型代码 [点击查看](https://github.com/modelscope/FunASR/tree/main/funasr/models/sense_voice)。
+- `vad_model`:表示开启 VAD,VAD 的作用是将长音频切割成短音频,此时推理耗时包括了 VAD 与 SenseVoice 总耗时,为链路耗时,如果需要单独测试 SenseVoice 模型耗时,可以关闭 VAD 模型。
+- `vad_kwargs`:表示 VAD 模型配置,`max_single_segment_time`: 表示 `vad_model` 最大切割音频时长,单位是毫秒 ms。
- `use_itn`:输出结果中是否包含标点与逆文本正则化。
-- `batch_size_s` 表示采用动态batch,batch中总音频时长,单位为秒s。
-- `merge_vad`:是否将 vad 模型切割的短音频碎片合成,合并后长度为`merge_length_s`,单位为秒s。
-- `ban_emo_unk`:禁用emo_unk标签,禁用后所有的句子都会被赋与情感标签。默认`False`
+- `batch_size_s` 表示采用动态 batch,batch 中总音频时长,单位为秒 s。
+- `merge_vad`:是否将 vad 模型切割的短音频碎片合成,合并后长度为 `merge_length_s`,单位为秒 s。
+- `ban_emo_unk`:禁用 emo_unk 标签,禁用后所有的句子都会被赋与情感标签。默认 `False`
+
-如果输入均为短音频(小于30s),并且需要批量化推理,为了加快推理效率,可以移除vad模型,并设置`batch_size`
+如果输入均为短音频(小于 30s),并且需要批量化推理,为了加快推理效率,可以移除 vad 模型,并设置 `batch_size`
```python
-model = AutoModel(model=model_dir, trust_remote_code=True, device="cuda:0")
+model = AutoModel (model=model_dir, trust_remote_code=True, device="cuda:0")
-res = model.generate(
+res = model.generate (
input=f"{model.model_path}/example/en.mp3",
cache={},
language="auto", # "zh", "en", "yue", "ja", "ko", "nospeech"
@@ -166,26 +174,26 @@ res = model.generate(
### 直接推理
-支持任意格式音频输入,输入音频时长限制在30s以下
+支持任意格式音频输入,输入音频时长限制在 30s 以下
```python
from model import SenseVoiceSmall
from funasr.utils.postprocess_utils import rich_transcription_postprocess
model_dir = "iic/SenseVoiceSmall"
-m, kwargs = SenseVoiceSmall.from_pretrained(model=model_dir, device="cuda:0")
-m.eval()
+m, kwargs = SenseVoiceSmall.from_pretrained (model=model_dir, device="cuda:0")
+m.eval ()
-res = m.inference(
- data_in=f"{kwargs['model_path']}/example/en.mp3",
+res = m.inference (
+ data_in=f"{kwargs ['model_path']}/example/en.mp3",
language="auto", # "zh", "en", "yue", "ja", "ko", "nospeech"
use_itn=False,
ban_emo_unk=False,
**kwargs,
)
-text = rich_transcription_postprocess(res[0][0]["text"])
-print(text)
+text = rich_transcription_postprocess (res [0][0]["text"])
+print (text)
```
## 服务部署
@@ -193,9 +201,11 @@ print(text)
Undo
### 导出与测试
-ONNX 与 Libtorch 导出
+
+ONNX 与 Libtorch 导出
#### ONNX
+
```python
# pip3 install -U funasr funasr-onnx
from pathlib import Path
@@ -205,17 +215,19 @@ from funasr_onnx.utils.postprocess_utils import rich_transcription_postprocess
model_dir = "iic/SenseVoiceSmall"
-model = SenseVoiceSmall(model_dir, batch_size=10, quantize=True)
+model = SenseVoiceSmall (model_dir, batch_size=10, quantize=True)
# inference
-wav_or_scp = ["{}/.cache/modelscope/hub/{}/example/en.mp3".format(Path.home(), model_dir)]
+wav_or_scp = ["{}/.cache/modelscope/hub/{}/example/en.mp3".format (Path.home (), model_dir)]
-res = model(wav_or_scp, language="auto", use_itn=True)
-print([rich_transcription_postprocess(i) for i in res])
+res = model (wav_or_scp, language="auto", use_itn=True)
+print ([rich_transcription_postprocess (i) for i in res])
```
-备注:ONNX模型导出到原模型目录中
+
+备注:ONNX 模型导出到原模型目录中
#### Libtorch
+
```python
from pathlib import Path
from funasr_torch import SenseVoiceSmall
@@ -224,20 +236,22 @@ from funasr_torch.utils.postprocess_utils import rich_transcription_postprocess
model_dir = "iic/SenseVoiceSmall"
-model = SenseVoiceSmall(model_dir, batch_size=10, device="cuda:0")
+model = SenseVoiceSmall (model_dir, batch_size=10, device="cuda:0")
-wav_or_scp = ["{}/.cache/modelscope/hub/{}/example/en.mp3".format(Path.home(), model_dir)]
+wav_or_scp = ["{}/.cache/modelscope/hub/{}/example/en.mp3".format (Path.home (), model_dir)]
-res = model(wav_or_scp, language="auto", use_itn=True)
-print([rich_transcription_postprocess(i) for i in res])
+res = model (wav_or_scp, language="auto", use_itn=True)
+print ([rich_transcription_postprocess (i) for i in res])
```
-备注:Libtorch模型导出到原模型目录中
+
+备注:Libtorch 模型导出到原模型目录中
### 部署
### 使用 FastAPI 部署
+
```shell
export SENSEVOICE_DEVICE=cuda:0
fastapi run --port 50000
@@ -255,17 +269,19 @@ pip3 install -e ./
### 数据准备
数据格式需要包括如下几个字段:
+
```text
{"key": "YOU0000008470_S0000238_punc_itn", "text_language": "<|en|>", "emo_target": "<|NEUTRAL|>", "event_target": "<|Speech|>", "with_or_wo_itn": "<|withitn|>", "target": "Including legal due diligence, subscription agreement, negotiation.", "source": "/cpfs01/shared/Group-speech/beinian.lzr/data/industrial_data/english_all/audio/YOU0000008470_S0000238.wav", "target_len": 7, "source_len": 140}
{"key": "AUD0000001556_S0007580", "text_language": "<|en|>", "emo_target": "<|NEUTRAL|>", "event_target": "<|Speech|>", "with_or_wo_itn": "<|woitn|>", "target": "there is a tendency to identify the self or take interest in what one has got used to", "source": "/cpfs01/shared/Group-speech/beinian.lzr/data/industrial_data/english_all/audio/AUD0000001556_S0007580.wav", "target_len": 18, "source_len": 360}
```
+
详细可以参考:`data/train_example.jsonl`
-数据准备细节介绍
+ 数据准备细节介绍
-- `key`: 数据唯一ID
+- `key`: 数据唯一 ID
- `source`:音频文件的路径
-- `source_len`:音频文件的fbank帧数
+- `source_len`:音频文件的 fbank 帧数
- `target`:音频文件标注文本
- `target_len`:音频文件标注文本长度
- `text_language`:音频文件的语种标签
@@ -273,23 +289,23 @@ pip3 install -e ./
- `event_target`:音频文件的事件标签
- `with_or_wo_itn`:标注文本中是否包含标点与逆文本正则化
-可以用指令 `sensevoice2jsonl` 从train_wav.scp、train_text.txt、train_text_language.txt、train_emo_target.txt和train_event_target.txt生成,准备过程如下:
+可以用指令 `sensevoice2jsonl` 从 train_wav.scp、train_text.txt、train_text_language.txt、train_emo_target.txt 和 train_event_target.txt 生成,准备过程如下:
`train_text.txt`
-左边为数据唯一ID,需与`train_wav.scp`中的`ID`一一对应
+左边为数据唯一 ID,需与 `train_wav.scp` 中的 `ID` 一一对应
右边为音频文件标注文本,格式如下:
```bash
BAC009S0764W0121 甚至出现交易几乎停滞的情况
BAC009S0916W0489 湖北一公司以员工名义贷款数十员工负债千万
-asr_example_cn_en 所有只要处理 data 不管你是做 machine learning 做 deep learning 做 data analytics 做 data science 也好 scientist 也好通通都要都做的基本功啊那 again 先先对有一些>也许对
+asr_example_cn_en 所有只要处理 data 不管你是做 machine learning 做 deep learning 做 data analytics 做 data science 也好 scientist 也好通通都要都做的基本功啊那 again 先先对有一些 > 也许对
ID0012W0014 he tried to think how it could be
```
`train_wav.scp`
-左边为数据唯一ID,需与`train_text.txt`中的`ID`一一对应
+左边为数据唯一 ID,需与 `train_text.txt` 中的 `ID` 一一对应
右边为音频文件的路径,格式如下
```bash
@@ -301,8 +317,8 @@ ID0012W0014 https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audi
`train_text_language.txt`
-左边为数据唯一ID,需与`train_text_language.txt`中的`ID`一一对应
-右边为音频文件的语种标签,支持`<|zh|>`、`<|en|>`、`<|yue|>`、`<|ja|>`和`<|ko|>`,格式如下
+左边为数据唯一 ID,需与 `train_text_language.txt` 中的 `ID` 一一对应
+右边为音频文件的语种标签,支持 `<|zh|>`、`<|en|>`、`<|yue|>`、`<|ja|>` 和 `<|ko|>`,格式如下
```bash
BAC009S0764W0121 <|zh|>
@@ -313,8 +329,8 @@ ID0012W0014 <|en|>
`train_emo.txt`
-左边为数据唯一ID,需与`train_emo.txt`中的`ID`一一对应
-右边为音频文件的情感标签,支持`<|HAPPY|>`、`<|SAD|>`、`<|ANGRY|>`、`<|NEUTRAL|>`、`<|FEARFUL|>`、`<|DISGUSTED|>`和`<|SURPRISED|>`,格式如下
+左边为数据唯一 ID,需与 `train_emo.txt` 中的 `ID` 一一对应
+右边为音频文件的情感标签,支持 `<|HAPPY|>`、`<|SAD|>`、`<|ANGRY|>`、`<|NEUTRAL|>`、`<|FEARFUL|>`、`<|DISGUSTED|>` 和 `<|SURPRISED|>`,格式如下
```bash
BAC009S0764W0121 <|NEUTRAL|>
@@ -325,8 +341,8 @@ ID0012W0014 <|NEUTRAL|>
`train_event.txt`
-左边为数据唯一ID,需与`train_event.txt`中的`ID`一一对应
-右边为音频文件的事件标签,支持`<|BGM|>`、`<|Speech|>`、`<|Applause|>`、`<|Laughter|>`、`<|Cry|>`、`<|Sneeze|>`、`<|Breath|>`和`<|Cough|>`,格式如下
+左边为数据唯一 ID,需与 `train_event.txt` 中的 `ID` 一一对应
+右边为音频文件的事件标签,支持 `<|BGM|>`、`<|Speech|>`、`<|Applause|>`、`<|Laughter|>`、`<|Cry|>`、`<|Sneeze|>`、`<|Breath|>` 和 `<|Cough|>`,格式如下
```bash
BAC009S0764W0121 <|Speech|>
@@ -336,6 +352,7 @@ ID0012W0014 <|Speech|>
```
`生成指令`
+
```shell
# generate train.jsonl and val.jsonl from wav.scp, text.txt, text_language.txt, emo_target.txt, event_target.txt
sensevoice2jsonl \
@@ -344,7 +361,8 @@ sensevoice2jsonl \
++jsonl_file_out="../../../data/list/train.jsonl"
```
-若无train_text_language.txt、train_emo_target.txt和train_event_target.txt,则自动通过使用`SenseVoice`模型对语种、情感和事件打标。
+若无 train_text_language.txt、train_emo_target.txt 和 train_event_target.txt,则自动通过使用 `SenseVoice` 模型对语种、情感和事件打标。
+
```shell
# generate train.jsonl and val.jsonl from wav.scp and text.txt
sensevoice2jsonl \
@@ -353,11 +371,12 @@ sensevoice2jsonl \
++jsonl_file_out="../../../data/list/train.jsonl" \
++model_dir='iic/SenseVoiceSmall'
```
+
### 启动训练
-注意修改 `finetune.sh` 中 `train_tool` 为你前面安装FunASR路径中`funasr/bin/train_ds.py`绝对路径
+注意修改 `finetune.sh` 中 `train_tool` 为你前面安装 FunASR 路径中 `funasr/bin/train_ds.py` 绝对路径
```shell
bash finetune.sh
@@ -373,16 +392,13 @@ python webui.py
## 优秀三方工作
-- Triton(GPU)部署最佳实践,triton + tensorrt,fp32测试,V100 GPU上加速比526,fp16支持中,[repo](https://github.com/modelscope/FunASR/blob/main/runtime/triton_gpu/README.md)
-- sherpa-onnx部署最佳实践,支持在10种编程语言里面使用 SenseVoice, 即 C++, C, Python, C#, Go, Swift, Kotlin, Java, JavaScript, Dart. 支持在 iOS, Android, Raspberry Pi 等平台使用SenseVoice,[repo](https://k2-fsa.github.io/sherpa/onnx/sense-voice/index.html)
+- Triton(GPU)部署最佳实践,triton + tensorrt,fp32 测试,V100 GPU 上加速比 526,fp16 支持中,[repo](https://github.com/modelscope/FunASR/blob/main/runtime/triton_gpu/README.md)
+- sherpa-onnx 部署最佳实践,支持在 10 种编程语言里面使用 SenseVoice, 即 C++, C, Python, C#, Go, Swift, Kotlin, Java, JavaScript, Dart. 支持在 iOS, Android, Raspberry Pi 等平台使用 SenseVoice,[repo](https://k2-fsa.github.io/sherpa/onnx/sense-voice/index.html)
# 联系我们
-如果您在使用中遇到问题,可以直接在github页面提Issues。欢迎语音兴趣爱好者扫描以下的钉钉群二维码加入社区群,进行交流和讨论。
+如果您在使用中遇到问题,可以直接在 github 页面提 Issues。欢迎语音兴趣爱好者扫描以下的钉钉群二维码加入社区群,进行交流和讨论。
| FunAudioLLM | FunASR |
|:----------------------------------------------------------------:|:--------------------------------------------------------:|
| 
|

|
-
-
-