| | |
| | | from funasr.utils.load_utils import load_audio_text_image_video,extract_fbank |
| | | from funasr.utils.datadir_writer import DatadirWriter |
| | | from torch.nn.utils.rnn import pad_sequence |
| | | from funasr.train_utils.device_funcs import to_device |
| | | |
| | | class VadStateMachine(Enum): |
| | | kVadInStateStartPointNotDetected = 1 |
| | |
| | | meta_data[ |
| | | "batch_data_time"] = speech_lengths.sum().item() * frontend.frame_shift * frontend.lfr_n / 1000 |
| | | |
| | | speech.to(device=kwargs["device"]), speech_lengths.to(device=kwargs["device"]) |
| | | speech = speech.to(device=kwargs["device"]) |
| | | speech_lengths = speech_lengths.to(device=kwargs["device"]) |
| | | |
| | | # b. Forward Encoder streaming |
| | | t_offset = 0 |
| | |
| | | "cache": cache |
| | | } |
| | | |
| | | |
| | | |
| | | batch = to_device(batch, device=kwargs["device"]) |
| | | segments_part, cache = self.forward(**batch) |
| | | if segments_part: |
| | | for batch_num in range(0, batch_size): |
| | |
| | | results = [] |
| | | for i in range(batch_size): |
| | | |
| | | if "MODELSCOPE_ENVIRONMENT" in os.environ and os.environ["MODELSCOPE_ENVIRONMENT"] == "eas": |
| | | results[i] = json.dumps(results[i]) |
| | | |
| | | if ibest_writer is not None: |
| | | ibest_writer["text"][key[i]] = segments[i] |
| | | |
| | | result_i = {"key": key[i], "value": segments[i]} |
| | | results.append(result_i) |
| | | |
| | | |
| | | if "MODELSCOPE_ENVIRONMENT" in os.environ and os.environ["MODELSCOPE_ENVIRONMENT"] == "eas": |
| | | results[i] = json.dumps(results[i]) |
| | | |
| | | return results, meta_data |
| | | |
| | | def DetectCommonFrames(self) -> int: |