FireRedTeam commited on
Commit
bbceaf3
·
verified ·
1 Parent(s): abeb0ce

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +494 -0
README.md ADDED
@@ -0,0 +1,494 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ language:
4
+ - en
5
+ - zh
6
+ tags:
7
+ - Punctuation-Restoration
8
+ - Punctuation-Prediction
9
+ - Token Classification
10
+ - transformers
11
+ - BERT
12
+ - LERT
13
+ - audio
14
+ - automatic-speech-recognition
15
+ - asr
16
+ ---
17
+
18
+ <div align="center">
19
+ <h1>
20
+ FireRedASR2S
21
+ <br>
22
+ A SOTA Industrial-Grade All-in-One ASR System
23
+ </h1>
24
+
25
+ </div>
26
+
27
+ [[Paper]](https://arxiv.org/pdf/2501.14350)
28
+ [[Model]](https://huggingface.co/FireRedTeam)
29
+ [[Blog]](https://fireredteam.github.io/demos/firered_asr/)
30
+ [[Demo]](https://huggingface.co/spaces/FireRedTeam/FireRedASR)
31
+
32
+
33
+ FireRedASR2S is a state-of-the-art (SOTA), industrial-grade, all-in-one ASR system with ASR, VAD, LID, and Punc modules. All modules achieve SOTA performance:
34
+ - **FireRedASR2**: Automatic Speech Recognition (ASR) supporting Chinese (Mandarin, 20+ dialects/accents), English, code-switching, and singing lyrics recognition. 2.89% average CER on Mandarin (4 test sets), 11.55% on Chinese dialects (19 test sets), outperforming Doubao-ASR, Qwen3-ASR-1.7B, Fun-ASR, and Fun-ASR-Nano-2512. FireRedASR2-AED also supports word-level timestamps and confidence scores.
35
+ - **FireRedVAD**: Voice Activity Detection (VAD) supporting speech/singing/music in 100+ languages. 97.57% F1, outperforming Silero-VAD, TEN-VAD, and FunASR-VAD. Supports non-streaming/streaming VAD and Audio Event Detection.
36
+ - **FireRedLID**: Spoken Language Identification (LID) supporting 100+ languages and 20+ Chinese dialects/accents. 97.18% accuracy, outperforming Whisper and SpeechBrain-LID.
37
+ - **FireRedPunc**: Punctuation Prediction (Punc) for Chinese and English. 78.90% average F1, outperforming FunASR-Punc (62.77%).
38
+
39
+ *`2S`: `2`nd-generation FireRedASR, now expanded to an all-in-one ASR `S`ystem*
40
+
41
+
42
+ ## 🔥 News
43
+ - [2026.02.12] We release FireRedASR2S (FireRedASR2-AED, FireRedVAD, FireRedLID, and FireRedPunc) with model weights and inference code. Download links below. Technical report and finetuning code coming soon.
44
+
45
+
46
+
47
+ ## Available Models and Languages
48
+
49
+ |Model|Supported Languages & Dialects|Download|
50
+ |:-------------:|:---------------------------------:|:----------:|
51
+ |FireRedASR2| Chinese (Mandarin and 20+ dialects/accents<sup>*</sup>), English, Code-Switching | [🤗](https://huggingface.co/FireRedTeam/FireRedASR2-AED) \| [🤖](https://modelscope.cn/collections/FireRedTeam/FireRedASR2S)|
52
+ |FireRedVAD | 100+ languages, 20+ Chinese dialects/accents<sup>*</sup> | [🤗](https://huggingface.co/FireRedTeam/FireRedVAD) \| [🤖](https://modelscope.cn/collections/FireRedTeam/FireRedVAD)|
53
+ |FireRedLID | 100+ languages, 20+ Chinese dialects/accents<sup>*</sup> | [🤗](https://huggingface.co/FireRedTeam/FireRedLID) \| [🤖](https://modelscope.cn/collections/FireRedTeam/FireRedLID)|
54
+ |FireRedPunc| Chinese, English | [🤗](https://huggingface.co/FireRedTeam/FireRedPunc) \| [🤖](https://modelscope.cn/collections/FireRedTeam/FireRedPunc)|
55
+
56
+ <sup>*</sup>Supported Chinese dialects/accents: Cantonese (Hong Kong & Guangdong), Sichuan, Shanghai, Wu, Minnan, Anhui, Fujian, Gansu, Guizhou, Hebei, Henan, Hubei, Hunan, Jiangxi, Liaoning, Ningxia, Shaanxi, Shanxi, Shandong, Tianjin, Yunnan, etc.
57
+
58
+
59
+
60
+ ## Method
61
+ ### FireRedASR2
62
+ FireRedASR2 builds upon [FireRedASR](https://github.com/FireRedTeam/FireRedASR) with improved accuracy, designed to meet diverse requirements in superior performance and optimal efficiency across various applications. It comprises two variants:
63
+ - **FireRedASR2-LLM**: Designed to achieve state-of-the-art performance and to enable seamless end-to-end speech interaction. It adopts an Encoder-Adapter-LLM framework leveraging large language model (LLM) capabilities.
64
+ - **FireRedASR2-AED**: Designed to balance high performance and computational efficiency and to serve as an effective speech representation module in LLM-based speech models. It utilizes an Attention-based Encoder-Decoder (AED) architecture.
65
+
66
+
67
+ ### Other Modules
68
+ - **FireRedVAD**: DFSMN-based non-streaming/streaming Voice Activity Detection and Audio Event Detection.
69
+ - **FireRedLID**: FireRedASR2-based Spoken Language Identification. See [FireRedLID README](./fireredasr2s/fireredlid/README.md) for language details.
70
+ - **FireRedPunc**: BERT-based Punctuation Prediction.
71
+
72
+
73
+ ## Evaluation
74
+ ### FireRedASR2
75
+ Metrics: Character Error Rate (CER%) for Chinese and Word Error Rate (WER%) for English. Lower is better.
76
+
77
+ We evaluate FireRedASR2 on 24 public test sets covering Mandarin, 20+ Chinese dialects/accents, and singing.
78
+
79
+ - **Mandarin (4 test sets)**: 2.89% (LLM) / 3.05% (AED) average CER, outperforming Doubao-ASR (3.69%), Qwen3-ASR-1.7B (3.76%), Fun-ASR (4.16%) and Fun-ASR-Nano-2512 (4.55%).
80
+ - **Dialects (19 test sets)**: 11.55% (LLM) / 11.67% (AED) average CER, outperforming Doubao-ASR (15.39%), Qwen3-ASR-1.7B (11.85%), Fun-ASR (12.76%) and Fun-ASR-Nano-2512 (15.07%).
81
+
82
+ *Note: ws=WenetSpeech, md=MagicData, conv=Conversational, daily=Daily-use.*
83
+
84
+ |ID|Testset\Model|FireRedASR2-LLM|FireRedASR2-AED|Doubao-ASR|Qwen3-ASR|Fun-ASR|Fun-ASR-Nano|
85
+ |:--:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|:-----:|
86
+ | |**Average CER<br>(All, 1-24)** |**9.67** |**9.80** |12.98 |10.12 |10.92 |12.81 |
87
+ | |**Average CER<br>(Mandarin, 1-4)** |**2.89** |**3.05** |3.69 |3.76 |4.16 |4.55 |
88
+ | |**Average CER<br>(Dialects, 5-23)** |**11.55**|**11.67**|15.39|11.85|12.76|15.07|
89
+ |1 |aishell1 |0.64 |0.57 |1.52 |1.48 |1.64 |1.96 |
90
+ |2 |aishell2 |2.15 |2.51 |2.77 |2.71 |2.38 |3.02 |
91
+ |3 |ws-net |4.44 |4.57 |5.73 |4.97 |6.85 |6.93 |
92
+ |4 |ws-meeting |4.32 |4.53 |4.74 |5.88 |5.78 |6.29 |
93
+ |5 |kespeech |3.08 |3.60 |5.38 |5.10 |5.36 |7.66 |
94
+ |6 |ws-yue-short |5.14 |5.15 |10.51|5.82 |7.34 |8.82 |
95
+ |7 |ws-yue-long |8.71 |8.54 |11.39|8.85 |10.14|11.36|
96
+ |8 |ws-chuan-easy |10.90|10.60|11.33|11.99|12.46|14.05|
97
+ |9 |ws-chuan-hard |20.71|21.35|20.77|21.63|22.49|25.32|
98
+ |10|md-heavy |7.42 |7.43 |7.69 |8.02 |9.13 |9.97 |
99
+ |11|md-yue-conv |12.23|11.66|26.25|9.76 |33.71|15.68|
100
+ |12|md-yue-daily |3.61 |3.35 |12.82|3.66 |2.69 |5.67 |
101
+ |13|md-yue-vehicle |4.50 |4.83 |8.66 |4.28 |6.00 |7.04 |
102
+ |14|md-chuan-conv |13.18|13.07|11.77|14.35|14.01|17.11|
103
+ |15|md-chuan-daily |4.90 |5.17 |3.90 |4.93 |3.98 |5.95 |
104
+ |16|md-shanghai-conv |28.70|27.02|45.15|29.77|25.49|37.08|
105
+ |17|md-shanghai-daily |24.94|24.18|44.06|23.93|12.55|28.77|
106
+ |18|md-wu |7.15 |7.14 |7.70 |7.57 |10.63|10.56|
107
+ |19|md-zhengzhou-conv |10.20|10.65|9.83 |9.55 |10.85|13.09|
108
+ |20|md-zhengzhou-daily|5.80 |6.26 |5.77 |5.88 |6.29 |8.18 |
109
+ |21|md-wuhan |9.60 |10.81|9.94 |10.22|4.34 |8.70 |
110
+ |22|md-tianjin |15.45|15.30|15.79|16.16|19.27|22.03|
111
+ |23|md-changsha |23.18|25.64|23.76|23.70|25.66|29.23|
112
+ |24|opencpop |1.12 |1.17 |4.36 |2.57 |3.05 |2.95 |
113
+
114
+ Doubao-ASR (volc.seedasr.auc) tested in early February 2026, and Fun-ASR tested in late November 2025. Our ASR training data does not include any Chinese dialect or accented speech data from MagicData.
115
+ - Doubao-ASR (API): https://www.volcengine.com/docs/6561/1354868
116
+ - Qwen3-ASR (1.7B): https://github.com/QwenLM/Qwen3-ASR
117
+ - Fun-ASR (API): https://help.aliyun.com/zh/model-studio/recording-file-recognition
118
+ - Fun-ASR-Nano-2512: https://huggingface.co/FunAudioLLM/Fun-ASR-Nano-2512
119
+
120
+
121
+ ### FireRedVAD
122
+ We evaluate FireRedVAD on FLEURS-VAD-102, a multilingual VAD benchmark covering 102 languages.
123
+
124
+ FireRedVAD achieves SOTA performance, outperforming Silero-VAD, TEN-VAD, FunASR-VAD, and WebRTC-VAD.
125
+
126
+ |Metric\Model|FireRedVAD|[Silero-VAD](https://github.com/snakers4/silero-vad)|[TEN-VAD](https://github.com/TEN-framework/ten-vad)|[FunASR-VAD](https://modelscope.cn/models/iic/speech_fsmn_vad_zh-cn-16k-common-pytorch)|[WebRTC-VAD](https://github.com/wiseman/py-webrtcvad)|
127
+ |:-------:|:-----:|:------:|:------:|:------:|:------:|
128
+ |AUC-ROC↑ |**99.60**|97.99|97.81|- |- |
129
+ |F1 score↑ |**97.57**|95.95|95.19|90.91|52.30|
130
+ |False Alarm Rate↓ |**2.69** |9.41 |15.47|44.03|2.83 |
131
+ |Miss Rate↓|3.62 |3.95 |2.95 |0.42 |64.15|
132
+
133
+ <sup>*</sup>FLEURS-VAD-102: We randomly selected ~100 audio files per language from [FLEURS test set](https://huggingface.co/datasets/google/fleurs), resulting in 9,443 audio files with manually annotated binary VAD labels (speech=1, silence=0). This VAD testset will be open sourced (coming soon).
134
+
135
+ Note: FunASR-VAD achieves low Miss Rate but at the cost of high False Alarm Rate (44.03%), indicating over-prediction of speech segments.
136
+
137
+
138
+ ### FireRedLID
139
+ Metric: Utterance-level LID Accuracy (%). Higher is better.
140
+
141
+ We evaluate FireRedLID on multilingual and Chinese dialect benchmarks.
142
+
143
+ FireRedLID achieves SOTA performance, outperforming Whisper, SpeechBrain-LID, and Dolphin.
144
+
145
+ |Testset\Model|Languages|FireRedLID|[Whisper](https://github.com/openai/whisper)|[SpeechBrain](https://huggingface.co/speechbrain/lang-id-voxlingua107-ecapa)|[Dolphin](https://github.com/DataoceanAI/Dolphin)|
146
+ |:-----------------:|:---------:|:---------:|:-----:|:---------:|:-----:|
147
+ |FLEURS test |82 languages |**97.18** |79.41 |92.91 |-|
148
+ |CommonVoice test |74 languages |**92.07** |80.81 |78.75 |-|
149
+ |KeSpeech + MagicData|20+ Chinese dialects/accents |**88.47** |-|-|69.01|
150
+
151
+
152
+ ### FireRedPunc
153
+ Metric: Precision/Recall/F1 Score (%). Higher is better.
154
+
155
+ We evaluate FireRedPunc on multi-domain Chinese and English benchmarks.
156
+
157
+ FireRedPunc achieves SOTA performance, outperforming FunASR-Punc (CT-Transformer).
158
+
159
+ |Testset\Model|#Sentences|FireRedPunc|[FunASR-Punc](https://www.modelscope.cn/models/iic/punc_ct-transformer_zh-cn-common-vocab272727-pytorch)|
160
+ |:------------------:|:---------:|:--------------:|:-----------------:|
161
+ |Multi-domain Chinese| 88,644 |**82.84 / 83.08 / 82.96** | 77.27 / 74.03 / 75.62 |
162
+ |Multi-domain English| 28,641 |**78.40 / 71.57 / 74.83** | 55.79 / 45.15 / 49.91 |
163
+ |Average F1 Score | - |**78.90** | 62.77 |
164
+
165
+
166
+
167
+
168
+ ## Quick Start
169
+ ### Setup
170
+ 1. Create a clean Python environment:
171
+ ```bash
172
+ $ conda create --name fireredasr2s python=3.10
173
+ $ conda activate fireredasr2s
174
+ $ git clone https://github.com/FireRedTeam/FireRedASR2S.git
175
+ $ cd FireRedASR2S # or fireredasr2s
176
+ ```
177
+
178
+ 2. Install dependencies and set up PATH and PYTHONPATH:
179
+ ```bash
180
+ $ pip install -r requirements.txt
181
+ $ export PATH=$PWD/fireredasr2s/:$PATH
182
+ $ export PYTHONPATH=$PWD/:$PYTHONPATH
183
+ ```
184
+
185
+ 3. Download models:
186
+ ```bash
187
+ # Download via ModelScope (recommended for users in China)
188
+ pip install -U modelscope
189
+ modelscope download --model FireRedTeam/FireRedASR2-AED --local_dir ./pretrained_models/FireRedASR2-AED
190
+ modelscope download --model FireRedTeam/FireRedVAD --local_dir ./pretrained_models/FireRedVAD
191
+ modelscope download --model FireRedTeam/FireRedLID --local_dir ./pretrained_models/FireRedLID
192
+ modelscope download --model FireRedTeam/FireRedPunc --local_dir ./pretrained_models/FireRedPunc
193
+
194
+ # Download via Hugging Face
195
+ pip install -U "huggingface_hub[cli]"
196
+ huggingface-cli download FireRedTeam/FireRedASR2-AED --local-dir ./pretrained_models/FireRedASR2-AED
197
+ huggingface-cli download FireRedTeam/FireRedVAD --local-dir ./pretrained_models/FireRedVAD
198
+ huggingface-cli download FireRedTeam/FireRedLID --local-dir ./pretrained_models/FireRedLID
199
+ huggingface-cli download FireRedTeam/FireRedPunc --local-dir ./pretrained_models/FireRedPunc
200
+ ```
201
+
202
+ 4. Convert your audio to **16kHz 16-bit mono PCM** format if needed:
203
+ ```bash
204
+ $ ffmpeg -i <input_audio_path> -ar 16000 -ac 1 -acodec pcm_s16le -f wav <output_wav_path>
205
+ ```
206
+
207
+ ### Script Usage
208
+ ```bash
209
+ $ cd examples_infer/asr_system
210
+ $ bash inference_asr_system.sh
211
+ ```
212
+
213
+ ### Command-line Usage
214
+ ```bash
215
+ $ fireredasr2s-cli --help
216
+ $ fireredasr2s-cli --wav_paths "assets/hello_zh.wav" "assets/hello_en.wav" --outdir output
217
+ $ cat output/result.jsonl
218
+ # {"uttid": "hello_zh", "text": "你好世界。", "sentences": [{"start_ms": 310, "end_ms": 1840, "text": "你好世界。", "asr_confidence": 0.875, "lang": "zh mandarin", "lang_confidence": 0.999}], "vad_segments_ms": [[310, 1840]], "dur_s": 2.32, "words": [{"start_ms": 490, "end_ms": 690, "text": "你"}, {"start_ms": 690, "end_ms": 1090, "text": "好"}, {"start_ms": 1090, "end_ms": 1330, "text": "世"}, {"start_ms": 1330, "end_ms": 1795, "text": "界"}], "wav_path": "assets/hello_zh.wav"}
219
+ # {"uttid": "hello_en", "text": "Hello speech.", "sentences": [{"start_ms": 120, "end_ms": 1840, "text": "Hello speech.", "asr_confidence": 0.833, "lang": "en", "lang_confidence": 0.998}], "vad_segments_ms": [[120, 1840]], "dur_s": 2.24, "words": [{"start_ms": 340, "end_ms": 1020, "text": "hello"}, {"start_ms": 1020, "end_ms": 1666, "text": "speech"}], "wav_path": "assets/hello_en.wav"}
220
+ ```
221
+
222
+ ### Python API Usage
223
+ ```python
224
+ from fireredasr2s import FireRedAsr2System, FireRedAsr2SystemConfig
225
+
226
+ asr_system_config = FireRedAsr2SystemConfig() # Use default config
227
+ asr_system = FireRedAsr2System(asr_system_config)
228
+
229
+ result = asr_system.process("assets/hello_zh.wav")
230
+ print(result)
231
+ # {'uttid': 'tmpid', 'text': '你好世界。', 'sentences': [{'start_ms': 440, 'end_ms': 1820, 'text': '你好世界。', 'asr_confidence': 0.868, 'lang': 'zh mandarin', 'lang_confidence': 0.999}], 'vad_segments_ms': [(440, 1820)], 'dur_s': 2.32, 'words': [], 'wav_path': 'assets/hello_zh.wav'}
232
+
233
+ result = asr_system.process("assets/hello_en.wav")
234
+ print(result)
235
+ # {'uttid': 'tmpid', 'text': 'Hello speech.', 'sentences': [{'start_ms': 260, 'end_ms': 1820, 'text': 'Hello speech.', 'asr_confidence': 0.933, 'lang': 'en', 'lang_confidence': 0.993}], 'vad_segments_ms': [(260, 1820)], 'dur_s': 2.24, 'words': [], 'wav_path': 'assets/hello_en.wav'}
236
+ ```
237
+
238
+
239
+
240
+ ## Usage of Each Module
241
+ The four components under `fireredasr2s`, i.e. `fireredasr2`, `fireredvad`, `fireredlid`, and `fireredpunc` are self-contained and designed to work as a standalone modules. You can use any of them independently without depending on the others. `FireRedVAD` and `FireRedLID` will also be open-sourced as standalone libraries in separate repositories.
242
+
243
+ ### Script Usage
244
+ ```bash
245
+ # ASR
246
+ $ cd examples_infer/asr
247
+ $ bash inference_asr_aed.sh
248
+ $ bash inference_asr_llm.sh
249
+
250
+ # VAD & AED (Audio Event Detection)
251
+ $ cd examples_infer/vad
252
+ $ bash inference_vad.sh
253
+ $ bash inference_streamvad.sh
254
+ $ bash inference_aed.sh
255
+
256
+ # LID
257
+ $ cd examples_infer/lid
258
+ $ bash inference_lid.sh
259
+
260
+ # Punc
261
+ $ cd examples_infer/punc
262
+ $ bash inference_punc.sh
263
+ ```
264
+
265
+
266
+ ### Python API Usage
267
+ Set up `PYTHONPATH` first: `export PYTHONPATH=$PWD/:$PYTHONPATH`
268
+
269
+ #### ASR
270
+ ```python
271
+ from fireredasr2s.fireredasr2 import FireRedAsr2, FireRedAsr2Config
272
+
273
+ batch_uttid = ["hello_zh", "hello_en"]
274
+ batch_wav_path = ["assets/hello_zh.wav", "assets/hello_en.wav"]
275
+
276
+ # FireRedASR2-AED
277
+ asr_config = FireRedAsr2Config(
278
+ use_gpu=True,
279
+ use_half=False,
280
+ beam_size=3,
281
+ nbest=1,
282
+ decode_max_len=0,
283
+ softmax_smoothing=1.25,
284
+ aed_length_penalty=0.6,
285
+ eos_penalty=1.0,
286
+ return_timestamp=True
287
+ )
288
+ model = FireRedAsr2.from_pretrained("aed", "pretrained_models/FireRedASR2-AED", asr_config)
289
+ results = model.transcribe(batch_uttid, batch_wav_path)
290
+ print(results)
291
+ # [{'uttid': 'hello_zh', 'text': '你好世界', 'confidence': 0.971, 'dur_s': 2.32, 'rtf': '0.0870', 'wav': 'assets/hello_zh.wav', 'timestamp': [('你', 0.42, 0.66), ('好', 0.66, 1.1), ('世', 1.1, 1.34), ('界', 1.34, 2.039)]}, {'uttid': 'hello_en', 'text': 'hello speech', 'confidence': 0.943, 'dur_s': 2.24, 'rtf': '0.0870', 'wav': 'assets/hello_en.wav', 'timestamp': [('hello', 0.34, 0.98), ('speech', 0.98, 1.766)]}]
292
+
293
+ # FireRedASR2-LLM
294
+ asr_config = FireRedAsr2Config(
295
+ use_gpu=True,
296
+ decode_min_len=0,
297
+ repetition_penalty=1.0,
298
+ llm_length_penalty=0.0,
299
+ temperature=1.0
300
+ )
301
+ model = FireRedAsr2.from_pretrained("llm", "pretrained_models/FireRedASR2-LLM", asr_config)
302
+ results = model.transcribe(batch_uttid, batch_wav_path)
303
+ print(results)
304
+ # [{'uttid': 'hello_zh', 'text': '你好世界', 'rtf': '0.0681', 'wav': 'assets/hello_zh.wav'}, {'uttid': 'hello_en', 'text': 'hello speech', 'rtf': '0.0681', 'wav': 'assets/hello_en.wav'}]
305
+ ```
306
+
307
+
308
+ #### VAD
309
+ ```python
310
+ from fireredasr2s.fireredvad import FireRedVad, FireRedVadConfig
311
+
312
+ vad_config = FireRedVadConfig(
313
+ use_gpu=False,
314
+ smooth_window_size=5,
315
+ speech_threshold=0.4,
316
+ min_speech_frame=20,
317
+ max_speech_frame=2000,
318
+ min_silence_frame=20,
319
+ merge_silence_frame=0,
320
+ extend_speech_frame=0,
321
+ chunk_max_frame=30000)
322
+ vad = FireRedVad.from_pretrained("pretrained_models/FireRedVAD/VAD", vad_config)
323
+
324
+ result, probs = vad.detect("assets/hello_zh.wav")
325
+
326
+ print(result)
327
+ # {'dur': 2.32, 'timestamps': [(0.44, 1.82)], 'wav_path': 'assets/hello_zh.wav'}
328
+ ```
329
+
330
+
331
+ #### Stream VAD
332
+ <details>
333
+ <summary>Click to expand</summary>
334
+
335
+ ```python
336
+ from fireredasr2s.fireredvad import FireRedStreamVad, FireRedStreamVadConfig
337
+
338
+ vad_config=FireRedStreamVadConfig(
339
+ use_gpu=False,
340
+ smooth_window_size=5,
341
+ speech_threshold=0.4,
342
+ pad_start_frame=5,
343
+ min_speech_frame=8,
344
+ max_speech_frame=2000,
345
+ min_silence_frame=20,
346
+ chunk_max_frame=30000)
347
+ stream_vad = FireRedStreamVad.from_pretrained("pretrained_models/FireRedVAD/Stream-VAD", vad_config)
348
+
349
+ frame_results, result = stream_vad.detect_full("assets/hello_zh.wav")
350
+
351
+ print(result)
352
+ # {'dur': 2.32, 'timestamps': [(0.46, 1.84)], 'wav_path': 'assets/hello_zh.wav'}
353
+ ```
354
+ </details>
355
+
356
+
357
+ #### Audio Event Detection (AED)
358
+ <details>
359
+ <summary>Click to expand</summary>
360
+
361
+ ```python
362
+ from fireredasr2s.fireredvad import FireRedAed, FireRedAedConfig
363
+
364
+ aed_config=FireRedAedConfig(
365
+ use_gpu=False,
366
+ smooth_window_size=5,
367
+ speech_threshold=0.4,
368
+ singing_threshold=0.5,
369
+ music_threshold=0.5,
370
+ min_event_frame=20,
371
+ max_event_frame=2000,
372
+ min_silence_frame=20,
373
+ merge_silence_frame=0,
374
+ extend_speech_frame=0,
375
+ chunk_max_frame=30000)
376
+ aed = FireRedAed.from_pretrained("pretrained_models/FireRedVAD/AED", aed_config)
377
+
378
+ result, probs = aed.detect("assets/event.wav")
379
+
380
+ print(result)
381
+ # {'dur': 22.016, 'event2timestamps': {'speech': [(0.4, 3.56), (3.66, 9.08), (9.27, 9.77), (10.78, 21.76)], 'singing': [(1.79, 19.96), (19.97, 22.016)], 'music': [(0.09, 12.32), (12.33, 22.016)]}, 'event2ratio': {'speech': 0.848, 'singing': 0.905, 'music': 0.991}, 'wav_path': 'assets/event.wav'}
382
+ ```
383
+ </details>
384
+
385
+
386
+ #### LID
387
+ <details>
388
+ <summary>Click to expand</summary>
389
+
390
+ ```python
391
+ from fireredasr2s.fireredlid import FireRedLid, FireRedLidConfig
392
+
393
+ batch_uttid = ["hello_zh", "hello_en"]
394
+ batch_wav_path = ["assets/hello_zh.wav", "assets/hello_en.wav"]
395
+
396
+ config = FireRedLidConfig(use_gpu=True, use_half=False)
397
+ model = FireRedLid.from_pretrained("pretrained_models/FireRedLID", config)
398
+
399
+ results = model.process(batch_uttid, batch_wav_path)
400
+ print(results)
401
+ # [{'uttid': 'hello_zh', 'lang': 'zh mandarin', 'confidence': 0.996, 'dur_s': 2.32, 'rtf': '0.0741', 'wav': 'assets/hello_zh.wav'}, {'uttid': 'hello_en', 'lang': 'en', 'confidence': 0.996, 'dur_s': 2.24, 'rtf': '0.0741', 'wav': 'assets/hello_en.wav'}]
402
+ ```
403
+ </details>
404
+
405
+
406
+ #### Punc
407
+ <details>
408
+ <summary>Click to expand</summary>
409
+
410
+ ```python
411
+ from fireredasr2s.fireredpunc.punc import FireRedPunc, FireRedPuncConfig
412
+
413
+ config = FireRedPuncConfig(use_gpu=True)
414
+ model = FireRedPunc.from_pretrained("pretrained_models/FireRedPunc", config)
415
+
416
+ batch_text = ["你好世界", "Hello world"]
417
+ results = model.process(batch_text)
418
+
419
+ print(results)
420
+ # [{'punc_text': '你好世界。', 'origin_text': '你好世界'}, {'punc_text': 'Hello world!', 'origin_text': 'Hello world'}]
421
+ ```
422
+ </details>
423
+
424
+
425
+ #### ASR System
426
+ ```python
427
+ from fireredasr2s.fireredasr2 import FireRedAsr2Config
428
+ from fireredasr2s.fireredlid import FireRedLidConfig
429
+ from fireredasr2s.fireredpunc import FireRedPuncConfig
430
+ from fireredasr2s.fireredvad import FireRedVadConfig
431
+ from fireredasr2s import FireRedAsr2System, FireRedAsr2SystemConfig
432
+
433
+ vad_config = FireRedVadConfig(
434
+ use_gpu=False,
435
+ smooth_window_size=5,
436
+ speech_threshold=0.4,
437
+ min_speech_frame=20,
438
+ max_speech_frame=2000,
439
+ min_silence_frame=20,
440
+ merge_silence_frame=0,
441
+ extend_speech_frame=0,
442
+ chunk_max_frame=30000
443
+ )
444
+ lid_config = FireRedLidConfig(use_gpu=True, use_half=False)
445
+ asr_config = FireRedAsr2Config(
446
+ use_gpu=True,
447
+ use_half=False,
448
+ beam_size=3,
449
+ nbest=1,
450
+ decode_max_len=0,
451
+ softmax_smoothing=1.25,
452
+ aed_length_penalty=0.6,
453
+ eos_penalty=1.0,
454
+ return_timestamp=True
455
+ )
456
+ punc_config = FireRedPuncConfig(use_gpu=True)
457
+
458
+ asr_system_config = FireRedAsr2SystemConfig(
459
+ "pretrained_models/FireRedVAD/VAD",
460
+ "pretrained_models/FireRedLID",
461
+ "aed", "pretrained_models/FireRedASR2-AED",
462
+ "pretrained_models/FireRedPunc",
463
+ vad_config, lid_config, asr_config, punc_config,
464
+ enable_vad=1, enable_lid=1, enable_punc=1
465
+ )
466
+ asr_system = FireRedAsr2System(asr_system_config)
467
+
468
+ batch_uttid = ["hello_zh", "hello_en"]
469
+ batch_wav_path = ["assets/hello_zh.wav", "assets/hello_en.wav"]
470
+ for wav_path, uttid in zip(batch_wav_path, batch_uttid):
471
+ result = asr_system.process(wav_path, uttid)
472
+ print(result)
473
+ # {'uttid': 'hello_zh', 'text': '你好世界。', 'sentences': [{'start_ms': 440, 'end_ms': 1820, 'text': '你好世界。', 'asr_confidence': 0.868, 'lang': 'zh mandarin', 'lang_confidence': 0.999}], 'vad_segments_ms': [(440, 1820)], 'dur_s': 2.32, 'words': [{'start_ms': 540, 'end_ms': 700, 'text': '你'}, {'start_ms': 700, 'end_ms': 1100, 'text': '好'}, {'start_ms': 1100, 'end_ms': 1300, 'text': '世'}, {'start_ms': 1300, 'end_ms': 1765, 'text': '界'}], 'wav_path': 'assets/hello_zh.wav'}
474
+ # {'uttid': 'hello_en', 'text': 'Hello speech.', 'sentences': [{'start_ms': 260, 'end_ms': 1820, 'text': 'Hello speech.', 'asr_confidence': 0.933, 'lang': 'en', 'lang_confidence': 0.993}], 'vad_segments_ms': [(260, 1820)], 'dur_s': 2.24, 'words': [{'start_ms': 400, 'end_ms': 960, 'text': 'hello'}, {'start_ms': 960, 'end_ms': 1666, 'text': 'speech'}], 'wav_path': 'assets/hello_en.wav'}
475
+ ```
476
+
477
+
478
+
479
+ ## FAQ
480
+ **Q: What audio format is supported?**
481
+
482
+ 16kHz 16-bit mono PCM wav. Use ffmpeg to convert other formats: `ffmpeg -i <input_audio_path> -ar 16000 -ac 1 -acodec pcm_s16le -f wav <output_wav_path>`
483
+
484
+ **Q: What are the input length limitations of ASR models?**
485
+
486
+ - FireRedASR2-AED supports audio input up to 60s. Input longer than 60s may cause hallucination issues, and input exceeding 200s will trigger positional encoding errors.
487
+ - FireRedASR2-LLM supports audio input up to 30s. The behavior for longer input is untested.
488
+
489
+
490
+ ## Acknowledgements
491
+ Thanks to the following open-source works:
492
+ - [Qwen](https://huggingface.co/Qwen)
493
+ - [WenetSpeech-Yue](https://github.com/ASLP-lab/WenetSpeech-Yue)
494
+ - [WenetSpeech-Chuan](https://github.com/ASLP-lab/WenetSpeech-Chuan)