| | |
| | | res = model.generate(input=wav_file) |
| | | print(res) |
| | | ``` |
| | | Note: The output format of the VAD model is: `[[beg1, end1], [beg2, end2], ..., [begN, endN]]`, where `begN/endN` indicates the starting/ending point of the `N-th` valid audio segment, measured in milliseconds. |
| | | |
| | | ### Voice Activity Detection (Streaming) |
| | | ```python |
| | | from funasr import AutoModel |
| | |
| | | if len(res[0]["value"]): |
| | | print(res) |
| | | ``` |
| | | Note: The output format for the streaming VAD model can be one of four scenarios: |
| | | - `[[beg1, end1], [beg2, end2], .., [begN, endN]]`:The same as the offline VAD output result mentioned above. |
| | | - `[[beg, -1]]`:Indicates that only a starting point has been detected. |
| | | - `[[-1, end]]`:Indicates that only an ending point has been detected. |
| | | - `[]`:Indicates that neither a starting point nor an ending point has been detected. |
| | | |
| | | The output is measured in milliseconds and represents the absolute time from the starting point. |
| | | ### Punctuation Restoration |
| | | ```python |
| | | from funasr import AutoModel |
| | |
| | | from funasr import AutoModel |
| | | # paraformer-zh is a multi-functional asr model |
| | | # use vad, punc, spk or not as you need |
| | | model = AutoModel(model="paraformer-zh", model_revision="v2.0.4", |
| | | vad_model="fsmn-vad", vad_model_revision="v2.0.4", |
| | | punc_model="ct-punc-c", punc_model_revision="v2.0.4", |
| | | # spk_model="cam++", spk_model_revision="v2.0.2", |
| | | model = AutoModel(model="paraformer-zh", vad_model="fsmn-vad", punc_model="ct-punc-c", |
| | | # spk_model="cam++" |
| | | ) |
| | | res = model.generate(input=f"{model.model_path}/example/asr_example.wav", |
| | | batch_size_s=300, |
| | |
| | | encoder_chunk_look_back = 4 #number of chunks to lookback for encoder self-attention |
| | | decoder_chunk_look_back = 1 #number of encoder chunks to lookback for decoder cross-attention |
| | | |
| | | model = AutoModel(model="paraformer-zh-streaming", model_revision="v2.0.4") |
| | | model = AutoModel(model="paraformer-zh-streaming") |
| | | |
| | | import soundfile |
| | | import os |
| | |
| | | ```python |
| | | from funasr import AutoModel |
| | | |
| | | model = AutoModel(model="fsmn-vad", model_revision="v2.0.4") |
| | | model = AutoModel(model="fsmn-vad") |
| | | |
| | | wav_file = f"{model.model_path}/example/asr_example.wav" |
| | | res = model.generate(input=wav_file) |
| | | print(res) |
| | | ``` |
| | | 注:VAD模型输出格式为:`[[beg1, end1], [beg2, end2], .., [begN, endN]]`,其中`begN/endN`表示第`N`个有效音频片段的起始点/结束点, |
| | | 单位为毫秒。 |
| | | |
| | | ### 语音端点检测(实时) |
| | | ```python |
| | | from funasr import AutoModel |
| | | |
| | | chunk_size = 200 # ms |
| | | model = AutoModel(model="fsmn-vad", model_revision="v2.0.4") |
| | | model = AutoModel(model="fsmn-vad") |
| | | |
| | | import soundfile |
| | | |
| | |
| | | if len(res[0]["value"]): |
| | | print(res) |
| | | ``` |
| | | 注:流式VAD模型输出格式为4种情况: |
| | | - `[[beg1, end1], [beg2, end2], .., [begN, endN]]`:同上离线VAD输出结果。 |
| | | - `[[beg, -1]]`:表示只检测到起始点。 |
| | | - `[[-1, end]]`:表示只检测到结束点。 |
| | | - `[]`:表示既没有检测到起始点,也没有检测到结束点 |
| | | 输出结果单位为毫秒,从起始点开始的绝对时间。 |
| | | |
| | | ### 标点恢复 |
| | | ```python |
| | | from funasr import AutoModel |
| | | |
| | | model = AutoModel(model="ct-punc", model_revision="v2.0.4") |
| | | model = AutoModel(model="ct-punc") |
| | | |
| | | res = model.generate(input="那今天的会就到这里吧 happy new year 明年见") |
| | | print(res) |
| | |
| | | ```python |
| | | from funasr import AutoModel |
| | | |
| | | model = AutoModel(model="fa-zh", model_revision="v2.0.0") |
| | | model = AutoModel(model="fa-zh") |
| | | |
| | | wav_file = f"{model.model_path}/example/asr_example.wav" |
| | | text_file = f"{model.model_path}/example/text.txt" |
| | |
| | | |
| | | res = model.generate(input=wav_file) |
| | | print(res) |
| | | # [[beg1, end1], [beg2, end2], .., [begN, endN]] |
| | | # beg/end: ms |
| | | |
| | | |
| | | |
| | |
| | | # print(res) |
| | | if len(res[0]["value"]): |
| | | print(res) |
| | | |
| | | |
| | | # 1. [[beg1, end1], [beg2, end2], .., [begN, endN]]; [[beg, end]]; [[beg1, end1], [beg2, end2]] |
| | | # 2. [[beg, -1]] |
| | | # 3. [[-1, end]] |
| | | # beg/end: ms |