Run ASR with VAD segmentation, punctuation, and optional speaker diarization. Pipeline: 1. VAD: Segment audio into speech regions 2. ASR: Recognize each segment (sorted by length for efficient batching) 3. Timestamp merge: Combine per-segment timestamps with VAD offs
(self, input, input_len=None, **cfg)
| 596 | return asr_result_list |
| 597 | |
| 598 | def inference_with_vad(self, input, input_len=None, **cfg): |
| 599 | """Run ASR with VAD segmentation, punctuation, and optional speaker diarization. |
| 600 | |
| 601 | Pipeline: |
| 602 | 1. VAD: Segment audio into speech regions |
| 603 | 2. ASR: Recognize each segment (sorted by length for efficient batching) |
| 604 | 3. Timestamp merge: Combine per-segment timestamps with VAD offsets |
| 605 | 4. Punctuation: Add punctuation to combined text (if punc_model configured) |
| 606 | 5. Speaker diarization: Cluster speaker embeddings and assign labels (if spk_model configured) |
| 607 | |
| 608 | Args: |
| 609 | input: Audio file path, URL, or numpy array. |
| 610 | input_len: Not used (kept for interface consistency). |
| 611 | **cfg: Runtime parameters (same as generate()). |
| 612 | |
| 613 | Returns: |
| 614 | list[dict]: Results with fields: key, text, timestamp, sentence_info, raw_text. |
| 615 | """ |
| 616 | self._reset_runtime_configs() |
| 617 | if self.spk_model is not None and "output_timestamp" not in cfg: |
| 618 | cfg["output_timestamp"] = True |
| 619 | cfg["return_time_stamps"] = True |
| 620 | kwargs = self.kwargs |
| 621 | # step.1: compute the vad model |
| 622 | deep_update(self.vad_kwargs, cfg) |
| 623 | beg_vad = time.time() |
| 624 | res = self.inference( |
| 625 | input, input_len=input_len, model=self.vad_model, kwargs=self.vad_kwargs, **cfg |
| 626 | ) |
| 627 | end_vad = time.time() |
| 628 | |
| 629 | # FIX(gcf): concat the vad clips for sense vocie model for better aed |
| 630 | if cfg.get("merge_vad", False): |
| 631 | for i in range(len(res)): |
| 632 | res[i]["value"] = merge_vad( |
| 633 | res[i]["value"], kwargs.get("merge_length_s", 15) * 1000 |
| 634 | ) |
| 635 | |
| 636 | # step.2 compute asr model |
| 637 | model = self.model |
| 638 | deep_update(kwargs, cfg) |
| 639 | batch_size = max(int(kwargs.get("batch_size_s", 300)) * 1000, 1) |
| 640 | batch_size_threshold_ms = int(kwargs.get("batch_size_threshold_s", 60)) * 1000 |
| 641 | kwargs["batch_size"] = batch_size |
| 642 | |
| 643 | key_list, data_list = prepare_data_iterator( |
| 644 | input, input_len=input_len, data_type=kwargs.get("data_type", None) |
| 645 | ) |
| 646 | results_ret_list = [] |
| 647 | time_speech_total_all_samples = 1e-6 |
| 648 | |
| 649 | beg_total = time.time() |
| 650 | pbar_total = ( |
| 651 | tqdm(colour="red", total=len(res), dynamic_ncols=True) |
| 652 | if not kwargs.get("disable_pbar", False) |
| 653 | else None |
| 654 | ) |
| 655 | for i in range(len(res)): |