From 2cbebbb33435dc490b6a092f2e5903c7f0e3e33c Mon Sep 17 00:00:00 2001
From: zhifu gao <zhifu.gzf@alibaba-inc.com>
Date: 星期二, 31 一月 2023 17:54:02 +0800
Subject: [PATCH] Merge pull request #52 from alibaba-damo-academy/dev

---
 funasr/bin/asr_inference_paraformer_vad_punc.py |   18 ++++++++++++++----
 1 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/funasr/bin/asr_inference_paraformer_vad_punc.py b/funasr/bin/asr_inference_paraformer_vad_punc.py
index cb33b16..619e6fd 100644
--- a/funasr/bin/asr_inference_paraformer_vad_punc.py
+++ b/funasr/bin/asr_inference_paraformer_vad_punc.py
@@ -3,6 +3,7 @@
 import logging
 import sys
 import time
+import json
 from pathlib import Path
 from typing import Optional
 from typing import Sequence
@@ -234,6 +235,8 @@
 
         predictor_outs = self.asr_model.calc_predictor(enc, enc_len)
         pre_acoustic_embeds, pre_token_length, alphas, pre_peak_index = predictor_outs[0], predictor_outs[1], predictor_outs[2], predictor_outs[3]
+        if torch.max(pre_token_length) < 1:
+            return []
         pre_token_length = pre_token_length.round().long()
         decoder_outs = self.asr_model.cal_decoder_with_predictor(enc, enc_len, pre_acoustic_embeds, pre_token_length)
         decoder_out, ys_pad_lens = decoder_outs[0], decoder_outs[1]
@@ -601,7 +604,7 @@
                     results = speech2text(**batch)
                     if len(results) < 1:
                         hyp = Hypothesis(score=0.0, scores={}, states={}, yseq=[])
-                        results = [[" ", ["<space>"], [2], 0, 1, 6]] * nbest
+                        results = [[" ", ["sil"], [2], 0, 1, 6]] * nbest
                     time_end = time.time()
                     forward_time = time_end - time_beg
                     lfr_factor = results[0][-1]
@@ -635,9 +638,16 @@
                         text_postprocessed, time_stamp_postprocessed, word_lists = postprocessed_result[0], \
                                                                                    postprocessed_result[1], \
                                                                                    postprocessed_result[2]
-                        text_postprocessed_punc, punc_id_list = text2punc(word_lists, 20)
-                        text_postprocessed_punc_time_stamp = "predictions: {}  time_stamp: {}".format(
-                            text_postprocessed_punc, time_stamp_postprocessed)
+                        if len(word_lists) > 0: 
+                            text_postprocessed_punc, punc_id_list = text2punc(word_lists, 20)
+                            text_postprocessed_punc_time_stamp = json.dumps({"predictions": text_postprocessed_punc,
+                                                                             "time_stamp": time_stamp_postprocessed},
+                                                                            ensure_ascii=False)
+                        else:
+                            text_postprocessed_punc = ""
+                            punc_id_list = []
+                            text_postprocessed_punc_time_stamp = ""
+                            
                     else:
                         text_postprocessed = ""
                         time_stamp_postprocessed = ""

--
Gitblit v1.9.1