Update README.md

This commit is contained in:
speech_asr 2024-07-23 10:46:20 +00:00
parent 1c67e4b613
commit 3318d07470

View File

@ -125,13 +125,15 @@ print(text)
``` ```
参数说明: 参数说明:
- `model_dir`:模型名称,或本地磁盘中的模型路径。 - `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`表示开启VADVAD的作用是将长音频切割成短音频此时推理耗时包括了VAD与SenseVoice总耗时为链路耗时如果需要单独测试SenseVoice模型耗时可以关闭VAD模型。 - `vad_model`表示开启VADVAD的作用是将长音频切割成短音频此时推理耗时包括了VAD与SenseVoice总耗时为链路耗时如果需要单独测试SenseVoice模型耗时可以关闭VAD模型。
- `vad_kwargs`表示VAD模型配置,`max_single_segment_time`: 表示`vad_model`最大切割音频时长, 单位是毫秒ms。 - `vad_kwargs`表示VAD模型配置,`max_single_segment_time`: 表示`vad_model`最大切割音频时长, 单位是毫秒ms。
- `use_itn`:输出结果中是否包含标点与逆文本正则化。 - `use_itn`:输出结果中是否包含标点与逆文本正则化。
- `batch_size_s` 表示采用动态batchbatch中总音频时长单位为秒s。 - `batch_size_s` 表示采用动态batchbatch中总音频时长单位为秒s。
- `merge_vad`:是否将 vad 模型切割的短音频碎片合成,合并后长度为`merge_length_s`单位为秒s。 - `merge_vad`:是否将 vad 模型切割的短音频碎片合成,合并后长度为`merge_length_s`单位为秒s。
- `ban_emo_unk`禁用emo_unk标签禁用后所有的句子都会被赋与情感标签。默认`False`
如果输入均为短音频小于30s并且需要批量化推理为了加快推理效率可以移除vad模型并设置`batch_size`
```python ```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")
@ -147,28 +149,7 @@ res = model.generate(
更多详细用法,请参考 [文档](https://github.com/modelscope/FunASR/blob/main/docs/tutorial/README.md) 更多详细用法,请参考 [文档](https://github.com/modelscope/FunASR/blob/main/docs/tutorial/README.md)
### 直接推理
支持任意格式音频输入输入音频时长限制在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")
res = m.inference(
data_in=f"{kwargs['model_path']}/example/en.mp3",
language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
use_itn=False,
**kwargs,
)
text = rich_transcription_postprocess(res[0][0]["text"])
print(text)
```
## 模型下载 ## 模型下载
上面代码会自动下载模型,如果您需要离线下载好模型,可以通过下面代码,手动下载,之后指定模型本地路径即可。 上面代码会自动下载模型,如果您需要离线下载好模型,可以通过下面代码,手动下载,之后指定模型本地路径即可。