(audio_path, text)
| 163 | |
| 164 | |
| 165 | def separate_audiosep(audio_path, text): |
| 166 | device = get_runtime_device() |
| 167 | model = load_audiosep() |
| 168 | mixture, _ = librosa.load(audio_path, sr=AUDIOSEP_SR, mono=True) |
| 169 | input_len = mixture.shape[0] |
| 170 | |
| 171 | with torch.no_grad(): |
| 172 | conditions = model.query_encoder.get_query_embed( |
| 173 | modality='text', text=[text], device=device |
| 174 | ) |
| 175 | input_dict = { |
| 176 | "mixture": torch.Tensor(mixture)[None, None, :].to(device), |
| 177 | "condition": conditions, |
| 178 | } |
| 179 | if input_len > AUDIOSEP_SR * 10: |
| 180 | sep_audio = model.ss_model.chunk_inference(input_dict) |
| 181 | sep_audio = sep_audio.squeeze() |
| 182 | else: |
| 183 | sep_segment = model.ss_model(input_dict)["waveform"] |
| 184 | sep_audio = sep_segment.squeeze(0).squeeze(0).data.cpu().numpy() |
| 185 | sep_audio = sep_audio[:input_len] |
| 186 | |
| 187 | return (AUDIOSEP_SR, sep_audio) |
| 188 | |
| 189 | |
| 190 | def _flowsep_process_chunk(model, preprocessor, chunk_wav, text): |
no test coverage detected