FireRedTeam commited on
Commit
32150b6
·
verified ·
1 Parent(s): 30f77ea

Update README.md

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