IPitchDetector<T>
Interfaces · AiDotNet.Interfaces
Defines the contract for pitch (fundamental frequency) detection.
Known implementations: CREPE<T>, MelodyExtractor<T>, PitchDetectorBase<T>
For Beginners
Pitch is what makes a note sound “high” or “low”.
Technical definition:
- Pitch = perceived frequency of a sound
- F0 (fundamental frequency) = the lowest frequency component
- Measured in Hz (cycles per second)
Human voice pitch ranges:
- Bass: 80-300 Hz
- Baritone: 100-400 Hz
- Tenor: 130-500 Hz
- Alto: 175-700 Hz
- Soprano: 250-1000 Hz
Applications:
- Auto-tune / pitch correction (T-Pain effect)
- Music transcription (audio to sheet music)
- Karaoke scoring
- Speech therapy (monitoring pitch for dysphonia)
- Voice training for singing or public speaking
- Lie detection (pitch changes under stress)
Common algorithms:
- YIN: Fast, accurate for monophonic audio
- PYIN: Probabilistic YIN (handles uncertainty)
- CREPE: Neural network approach (most accurate)
- Autocorrelation: Classic signal processing method
How It Works
Pitch detection finds the fundamental frequency (F0) of periodic signals. This is essential for music analysis and speech processing.
Properties
| Property | Summary |
|---|---|
double MaxPitch { get; set; } |
Gets or sets the maximum detectable pitch in Hz. |
double MinPitch { get; set; } |
Gets or sets the minimum detectable pitch in Hz. |
int SampleRate { get; } |
Gets the sample rate this detector operates at. |
Methods
| Method | Summary |
|---|---|
IReadOnlyList<PitchFrame<T>> ExtractDetailedPitchContour(Tensor<T> audio, int hopSizeMs) |
Extracts pitch contour with voicing information. |
T MidiToPitch(double midiNote) |
Converts MIDI note number to pitch in Hz. |
T[] ExtractPitchContour(Tensor<T> audio, int hopSizeMs) |
Extracts pitch contour from audio (F0 over time). |
ValueTuple<T, T>? DetectPitchWithConfidence(Tensor<T> audioFrame) |
Detects pitch with confidence score. |
ValueTuple<bool, T> DetectPitch(Tensor<T> audioFrame) |
Detects the pitch of an audio frame. |
double GetCentsDeviation(T pitchHz) |
Calculates cents deviation from nearest note. |
double PitchToMidi(T pitchHz) |
Converts pitch in Hz to MIDI note number. |
string PitchToNoteName(T pitchHz) |
Gets the note name for a pitch. |