SenseVoice

30 downloads 0 likes on ModelScope updated

Model card

SenseVoice开源项目介绍

SenseVoice开源模型是多语言音频理解模型,具有包括语音识别、语种识别、语音情感识别,声学事件检测能力。

推理

modelscope pipeline推理

from modelscope.pipelines import pipeline
from modelscope.utils.constant import Tasks

inference_pipeline = pipeline(
    task=Tasks.auto_speech_recognition,
    model='iic/SenseVoiceSmall',
    model_revision="master",
    device="cuda:0",)

rec_result = inference_pipeline('https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav')
print(rec_result)

使用funasr推理

支持任意格式音频输入,支持任意时长输入

from funasr import AutoModel
from funasr.utils.postprocess_utils import rich_transcription_postprocess

model_dir = "iic/SenseVoiceSmall"


model = AutoModel(
    model=model_dir,
    trust_remote_code=True,
    remote_code="./model.py",  
    vad_model="fsmn-vad",
    vad_kwargs={"max_single_segment_time": 30000},
    device="cuda:0",
)

# en
res = model.generate(
    input=f"{model.model_path}/example/en.mp3",
    cache={},
    language="auto",  # "zn", "en", "yue", "ja", "ko", "nospeech"
    use_itn=True,
    batch_size_s=60,
    merge_vad=True,  #
    merge_length_s=15,
)
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 内部集成版本,此时修改当前目录下的model.py不会生效,因为加载的是funasr内部版本,模型代码点击查看。
  • 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
model = AutoModel(model=model_dir, trust_remote_code=True, device="cuda:0")

res = model.generate(
    input=f"{model.model_path}/example/en.mp3",
    cache={},
    language="auto", # "zn", "en", "yue", "ja", "ko", "nospeech"
    use_itn=True,
    batch_size=64, 
)