@@ -95,56 +95,42 @@ pip install -r requirements.txt
9595
9696## 推理
9797
98- ### 直接推理
99-
100- ``` python
101- from model import SenseVoiceSmall
102-
103- model_dir = " iic/SenseVoiceSmall"
104- m, kwargs = SenseVoiceSmall.from_pretrained(model = model_dir)
10598
10699
107- res = m.inference(
108- data_in = " https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav" ,
109- language = " auto" , # "zn", "en", "yue", "ja", "ko", "nospeech"
110- use_itn = False ,
111- ** kwargs,
112- )
113-
114- print (res)
115- ```
116-
117100### 使用funasr推理
118101
102+ 支持任意格式音频输入,支持任意时长输入
103+
119104``` python
120105from funasr import AutoModel
121106from funasr.utils.postprocess_utils import rich_transcription_postprocess
122107
123108model_dir = " iic/SenseVoiceSmall"
124- input_file = (
125- " https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav"
126- )
127109
128- model = AutoModel(model = model_dir,
129- vad_model = " fsmn-vad" ,
130- vad_kwargs = {" max_single_segment_time" : 30000 },
131- trust_remote_code = True , device = " cuda:0" )
132110
111+ model = AutoModel(
112+ model = model_dir,
113+ vad_model = " fsmn-vad" ,
114+ vad_kwargs = {" max_single_segment_time" : 30000 },
115+ device = " cpu" ,
116+ )
117+
118+ # en
133119res = model.generate(
134- input = input_file ,
120+ input = f " { model.model_path } /example/en.mp3 " ,
135121 cache = {},
136- language = " auto" , # "zn", "en", "yue", "ja", "ko", "nospeech"
137- use_itn = False ,
138- batch_size_s = 0 ,
122+ language = " auto" , # "zn", "en", "yue", "ja", "ko", "nospeech"
123+ use_itn = True ,
124+ batch_size_s = 60 ,
125+ merge_vad = True , #
126+ merge_length_s = 15 ,
139127)
140-
141128text = rich_transcription_postprocess(res[0 ][" text" ])
142-
143129print (text)
144130```
145131
146132funasr版本已经集成了vad模型,支持任意时长音频输入,` batch_size_s ` 单位为秒。
147- 如果输入均为短音频,并且需要批量化推理,为了加快推理效率,可以移除vad模型,并设置` batch_size `
133+ 如果输入均为短音频(小于30s) ,并且需要批量化推理,为了加快推理效率,可以移除vad模型,并设置` batch_size `
148134
149135``` python
150136model = AutoModel(model = model_dir, trust_remote_code = True , device = " cuda:0" )
@@ -160,6 +146,27 @@ res = model.generate(
160146
161147更多详细用法,请参考 [ 文档] ( https://github.com/modelscope/FunASR/blob/main/docs/tutorial/README.md )
162148
149+ ### 直接推理
150+
151+ 支持任意格式音频输入,输入音频时长限制在30s以下
152+
153+ ``` python
154+ from model import SenseVoiceSmall
155+
156+ model_dir = " iic/SenseVoiceSmall"
157+ m, kwargs = SenseVoiceSmall.from_pretrained(model = model_dir)
158+
159+
160+ res = m.inference(
161+ data_in = " https://isv-data.oss-cn-hangzhou.aliyuncs.com/ics/MaaS/ASR/test_audio/asr_example_zh.wav" ,
162+ language = " auto" , # "zn", "en", "yue", "ja", "ko", "nospeech"
163+ use_itn = False ,
164+ ** kwargs,
165+ )
166+
167+ print (res)
168+ ```
169+
163170## 服务部署
164171
165172Undo
0 commit comments