Filter and threshold pitch and periodicity
masterTo handle noisy periodicity or quantization artifacts, use the filter and threshold submodules.
Common Workflow:
- Median Filter: Smooth noisy periodicity values using
torchcrepe.filter.median. - Thresholding: Remove inharmonic regions using
torchcrepe.threshold.At(threshold_value). - Smoothing: Remove quantization artifacts in pitch using
torchcrepe.filter.mean.
Specialized Thresholding:
torchcrepe.threshold.Hysteresis: Provides fine-grained control for removing spurious voiced regions caused by noise.torchcrepe.threshold.Silence(threshold_db): Manually sets periodicity to zero in silent regions (useful because CREPE may assign high confidence to silence).
# Example: 15ms window assuming 5ms hop length (win_length = 3)
win_length = 3
# 1. Median filter noisy confidence
periodicity = torchcrepe.filter.median(periodicity, win_length)
# 2. Remove inharmonic regions (e.g., threshold of 0.21)
pitch = torchcrepe.threshold.At(.21)(pitch, periodicity)
# 3. Smooth pitch to remove quantization artifacts
pitch = torchcrepe.filter.mean(pitch, win_length)
# Handling silence specifically
periodicity = torchcrepe.threshold.Silence(-60.)(periodicity, audio, sr, hop_length)