(audio_path, text)
| 224 | |
| 225 | |
| 226 | def separate_flowsep(audio_path, text): |
| 227 | device = get_runtime_device() |
| 228 | model, preprocessor = load_flowsep() |
| 229 | full_wav = preprocessor.load_full_audio(audio_path) |
| 230 | input_len = full_wav.shape[0] |
| 231 | |
| 232 | with torch.no_grad(): |
| 233 | if input_len <= FLOWSEP_CHUNK_IN: |
| 234 | sep_audio = _flowsep_process_chunk(model, preprocessor, full_wav.copy(), text) |
| 235 | else: |
| 236 | out_list = [] |
| 237 | start = 0 |
| 238 | while start < input_len: |
| 239 | end = min(start + FLOWSEP_CHUNK_IN, input_len) |
| 240 | chunk = full_wav[start:end] |
| 241 | out_chunk = _flowsep_process_chunk(model, preprocessor, chunk.copy(), text) |
| 242 | need = min(FLOWSEP_CHUNK_OUT, input_len - start) |
| 243 | out_list.append(out_chunk[:need]) |
| 244 | start += FLOWSEP_CHUNK_OUT |
| 245 | sep_audio = np.concatenate(out_list) |
| 246 | |
| 247 | if len(sep_audio) > input_len: |
| 248 | sep_audio = sep_audio[:input_len] |
| 249 | elif len(sep_audio) < input_len: |
| 250 | sep_audio = np.pad(sep_audio, (0, input_len - len(sep_audio)), mode="constant", constant_values=0) |
| 251 | |
| 252 | return (FLOWSEP_SR, sep_audio) |
| 253 | |
| 254 | |
| 255 | def inference(audio, text, model_choice): |
no test coverage detected