Skip to content

Commit

Permalink
Add an error message for channel number mismatch. (#2)
Browse files Browse the repository at this point in the history
* Add an error message for channel number mismatch.

* Update message
  • Loading branch information
yoshipon authored Jun 17, 2024
1 parent 383d05a commit 51e0bdb
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion neural_fcasa/separate.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@ def separate(src_filename: Path, dst_filename: Path, ctx: Context, args: Namespa
model, istft = ctx.model, ctx.istft

# load wav
src_wav, sr = sf.read(src_filename, dtype=np.float32)
src_wav, sr = sf.read(src_filename, dtype=np.float32, always_2d=True)
src_wav = rearrange(torch.from_numpy(src_wav).to(model.device), "t m -> 1 m t")

if src_wav.shape[1] != ctx.config.n_mic:
raise RuntimeError(
f"The number of input channels is {src_wav.shape[1]} but should be {ctx.config.n_mic}. "
"Please specify a {ctx.config.n_mic}-channel signal to `src_filename`."
)

# calculate spectrogram
xraw = model.stft(src_wav)[..., : src_wav.shape[-1] // model.hop_length] # [B, F, M, T]
scale = xraw.abs().square().clip(1e-6).mean(dim=(1, 2, 3), keepdims=True).sqrt()
Expand Down

0 comments on commit 51e0bdb

Please sign in to comment.