Skip to content

Commit dc815a0

Browse files
fix trajectory display for silent input channel
1 parent b3e59b2 commit dc815a0

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

pytch/audio.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,10 +430,18 @@ def compute_f0(self, audio, lvl):
430430
f0[:, c] = np.mean(f0_tmp) # take the center frame
431431
conf[:, c] = 1 - np.mean(conf_tmp)
432432
elif self.f0_algorithm == "SWIPE":
433-
if np.all(lvl > self.f0_lvl_threshold):
434-
f0, conf = self.rtswipe(audio)
435-
f0 = f0.reshape(1, -1)
436-
conf = conf.reshape(1, -1)
433+
# set silent channels to a low value to avoid NaN output of SWIPE
434+
discard_chs = np.argwhere(lvl.flatten() <= self.f0_lvl_threshold)
435+
audio[:, discard_chs] = 0.1
436+
437+
f0, conf = self.rtswipe(audio)
438+
439+
# fix invalid SWIPE output for silent channels
440+
f0[discard_chs] = 0.0
441+
conf[discard_chs] = 0.0
442+
443+
f0 = f0.reshape(1, -1)
444+
conf = conf.reshape(1, -1)
437445

438446
return f0, conf
439447

0 commit comments

Comments
 (0)