Skip to content

Commit

Permalink
Update pipeline.py
Browse files Browse the repository at this point in the history
  • Loading branch information
liuxubo717 authored Oct 17, 2023
1 parent 77a0e8b commit f4a0ff8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def build_audiosep(config_yaml, checkpoint_path, device):
return model


def inference(model, audio_file, text, output_file, device='cuda'):
def inference(model, audio_file, text, output_file, use_chunk=False, device='cuda'):
print(f'Separate audio from [{audio_file}] with textual query [{text}]')
mixture, fs = librosa.load(audio_file, sr=32000, mono=True)
with torch.no_grad():
Expand All @@ -41,9 +41,11 @@ def inference(model, audio_file, text, output_file, device='cuda'):
"condition": conditions,
}

sep_segment = model.ss_model(input_dict)["waveform"]

sep_segment = sep_segment.squeeze(0).squeeze(0).data.cpu().numpy()
if use_chunk:
sep_segment = model.ss_model.chunk_inference(input_dict)
else:
sep_segment = model.ss_model(input_dict)["waveform"]
sep_segment = sep_segment.squeeze(0).squeeze(0).data.cpu().numpy()

write(output_file, 32000, np.round(sep_segment * 32767).astype(np.int16))
print(f'Write separated audio to [{output_file}]')
Expand Down

0 comments on commit f4a0ff8

Please sign in to comment.