(model, preprocessor, chunk_wav, text)
| 188 | |
| 189 | |
| 190 | def _flowsep_process_chunk(model, preprocessor, chunk_wav, text): |
| 191 | device = get_runtime_device() |
| 192 | chunk_wav = preprocessor.preprocess_chunk(chunk_wav) |
| 193 | if len(chunk_wav) < FLOWSEP_CHUNK_IN: |
| 194 | pad = np.zeros(FLOWSEP_CHUNK_IN - len(chunk_wav), dtype=np.float32) |
| 195 | chunk_wav = np.concatenate([chunk_wav, pad]) |
| 196 | chunk_wav = chunk_wav[:FLOWSEP_CHUNK_IN] |
| 197 | mixed_mel, stft = preprocessor.wav_feature_extraction(chunk_wav.reshape(1, -1)) |
| 198 | batch = { |
| 199 | "fname": ["temp"], |
| 200 | "text": [text], |
| 201 | "caption": [text], |
| 202 | "waveform": torch.rand(1, 1, FLOWSEP_CHUNK_IN).to(device), |
| 203 | "log_mel_spec": torch.rand(1, 1024, 64).to(device), |
| 204 | "sampling_rate": torch.tensor([FLOWSEP_SR]).to(device), |
| 205 | "label_vector": torch.rand(1, 527).to(device), |
| 206 | "stft": torch.rand(1, 1024, 512).to(device), |
| 207 | "mixed_waveform": torch.from_numpy(chunk_wav.reshape(1, 1, FLOWSEP_CHUNK_IN)).to(device), |
| 208 | "mixed_mel": mixed_mel.reshape(1, mixed_mel.shape[0], mixed_mel.shape[1]).to(device), |
| 209 | } |
| 210 | result = model.generate_sample( |
| 211 | [batch], |
| 212 | name="temp_result", |
| 213 | unconditional_guidance_scale=1.0, |
| 214 | ddim_steps=20, |
| 215 | n_gen=1, |
| 216 | save=False, |
| 217 | save_mixed=False, |
| 218 | ) |
| 219 | if isinstance(result, np.ndarray): |
| 220 | out = result.squeeze() |
| 221 | else: |
| 222 | out = result.squeeze().cpu().numpy() |
| 223 | return out[:FLOWSEP_CHUNK_OUT] |
| 224 | |
| 225 | |
| 226 | def separate_flowsep(audio_path, text): |
no test coverage detected