|
28 | 28 | from funasr.train_utils.set_all_random_seed import set_all_random_seed |
29 | 29 | from funasr.train_utils.load_pretrained_model import load_pretrained_model |
30 | 30 | from funasr.utils import export_utils |
| 31 | +from funasr.utils.postprocess_hotwords import apply_postprocess_hotwords_to_results |
31 | 32 | from funasr.utils import misc |
32 | 33 |
|
33 | 34 |
|
@@ -458,6 +459,12 @@ def generate(self, input, input_len=None, progress_callback=None, **cfg): |
458 | 459 | **cfg: Runtime parameters: |
459 | 460 | - cache (dict): State cache for streaming mode. Pass {} for first call. |
460 | 461 | - hotword (str/list): Keywords to boost recognition accuracy. |
| 462 | + - postprocess_hotwords (str/list/dict): Text-level hotword correction after |
| 463 | + decoding. Unlike model-level ``hotword``, this runs on the final text. |
| 464 | + - postprocess_hotword_file (str): Hotword file path. Each line is a target |
| 465 | + word or an explicit mapping like ``错误词=>目标词``. |
| 466 | + - postprocess_hotword_threshold (float): Fuzzy match threshold in [0, 1]. |
| 467 | + - return_postprocess_hotword_matches (bool): Include replacement details. |
461 | 468 | - language (str): Language hint ("auto", "zh", "en", "Chinese", etc.) |
462 | 469 | - batch_size_s (int): Dynamic batch total duration in seconds. |
463 | 470 | - is_final (bool): Last chunk flag for streaming mode. |
@@ -486,12 +493,13 @@ def generate(self, input, input_len=None, progress_callback=None, **cfg): |
486 | 493 | if cfg.get("return_raw_text", self.kwargs.get("return_raw_text", False)): |
487 | 494 | result["raw_text"] = copy.copy(result["text"]) |
488 | 495 | result["text"] = punc_res[0]["text"] |
489 | | - return results |
| 496 | + return apply_postprocess_hotwords_to_results(results, cfg) |
490 | 497 |
|
491 | 498 | else: |
492 | | - return self.inference_with_vad( |
| 499 | + results = self.inference_with_vad( |
493 | 500 | input, input_len=input_len, progress_callback=progress_callback, **cfg |
494 | 501 | ) |
| 502 | + return apply_postprocess_hotwords_to_results(results, cfg) |
495 | 503 |
|
496 | 504 | def inference( |
497 | 505 | self, |
|
0 commit comments