A modern Android library for real-time pitch and chord detection straight from the device microphone, for tuners, etc. It captures audio, analyzes the frequency spectrum, and returns the detected note or chord — all with a pure Kotlin DSP core and no third-party audio libraries. First-class Jetpack Compose support is included out of the box.
This library is designed to simplify pitch and chord detection in your Android app with a robust set of features:
- 🎸 Note Detection: Detect individual notes (E, A, D, G, B, …) with the YIN pitch-detection algorithm for accurate, octave-error-resistant results.
- 🎶 Chord Detection: Recognize chords such as
Am,Bb,C,D,E,Em,Em7,Am7, andAsus2using chroma + template matching. - 🎚️ Tuning in Cents: Every detected note reports how flat/sharp it is, ready to drive a tuner needle.
- 🎻 Multi-Instrument Ready: Built-in
InstrumentProfilepresets (Guitar, Ukulele, Bass) — or supply your own custom tuning. - 🔇 Noise Handling: DC-offset removal, a high-pass filter, an energy gate, and temporal smoothing reduce background interference.
- ⚡ Real-Time & Efficient: A from-scratch FFT and coroutine-based
Flowpipeline keep detection fast and off the main thread. - 🚀 Jetpack Compose Support: A single composable handles the microphone permission (including the permanently-denied → Settings flow) and streams results back to you.
- No Third-Party Audio Dependencies: The entire signal-processing pipeline (FFT, pitch detection, chroma analysis) is implemented from scratch in Kotlin.
- Time-Saving: Provides a simple, out-of-the-box solution to microphone capture, permission handling, and DSP — saving significant development time.
- Boilerplate Reduction: Handles
AudioRecord, the runtime permission flow, and threading, letting you focus on your app's logic. - Typed Results: Returns a clean, typed
TuningResultyou can format, style, or drive UI from — not a fixed string.
| Jetpack Compose |
|---|
![]() |
- JDK Version:
17 - Target SDK:
37 - Minimum SDK:
28 - Kotlin Version:
2.4.21 - AGP Version:
9.4.1 - Gradle Version:
9.8.1 - Build Tool Version:
37
THE BETA RELEASES MAY CONTAIN MAJOR OR MINOR CHANGES.
ℹ️ Upgrading? Check the Migration Guide for renamed and deprecated APIs.
implementation 'com.github.NicosNicolaou16:PitchKit:1.0.2'allprojects {
repositories {
maven { url "https://jitpack.io" }
}
}implementation("com.github.NicosNicolaou16:PitchKit:1.0.2")dependencyResolutionManagement {
//...
repositories {
//...
maven { url = uri("https://jitpack.io") }
}
}[versions]
# other versions here...
pitchKit = "1.0.2"
[libraries]
# other libraries here...
pitch-kit = { group = "com.github.NicosNicolaou16", name = "PitchKit", version.ref = "pitchKit" }implementation(libs.pitch.kit)dependencyResolutionManagement {
//...
repositories {
//...
maven { url = uri("https://jitpack.io") }
}
}Drop PitchKitListener into any composable. It requests the microphone
permission, starts detection, and streams a typed TuningResult back through the
onResult callback. Detection stops automatically when the composable leaves the
composition.
@Composable
fun TunerScreen() {
var resultNote by remember { mutableStateOf("-") }
PitchKitListener { result ->
resultNote = when (result) {
is TuningResult.Note -> result.name
is TuningResult.Chord -> result.name
TuningResult.Silence -> "-"
}
}
Text(text = resultNote)
}TuningResult is a sealed class, so you can handle each case exhaustively and use
the numeric data (frequency, cents) however you like:
PitchKitListener { result ->
when (result) {
is TuningResult.Note -> {
// result.name -> "E", "A#", ...
// result.freq -> detected frequency in Hz
// result.cents -> deviation from perfect pitch (-50..+50)
}
is TuningResult.Chord -> {
// result.name -> "Am", "Cmaj7", ...
}
TuningResult.Silence -> {
// no sound / below threshold
}
}
}By default, the tuner is configured for a standard 6-string guitar. Pass a
different InstrumentProfile to tune another instrument:
// Built-in presets: InstrumentProfile.Guitar (default), .Ukulele, .Bass
PitchKitListener(profile = InstrumentProfile.Ukulele) { result ->
//...your code here
}You can also supply your own profile for custom tunings:
val dropD = InstrumentProfile(
name = "Drop D",
minFreq = 60.0,
maxFreq = 5000.0,
bassCeiling = 400.0,
harmonicPivot = 200.0,
openStrings = listOf(
InstrumentProfile.OpenString("D2", 73.42),
InstrumentProfile.OpenString("A2", 110.00),
InstrumentProfile.OpenString("D3", 146.83),
InstrumentProfile.OpenString("G3", 196.00),
InstrumentProfile.OpenString("B3", 246.94),
InstrumentProfile.OpenString("E4", 329.63),
),
)
PitchKitListener(profile = dropD) { result ->
//...your code here
}All popup strings are parameters, so you can localize or rebrand them.
Use onError to react when the microphone can't be used.
PitchKitListener(
titleText = "Microphone needed",
rationaleText = "This app needs microphone access to detect notes and chords.",
permanentlyDeniedText = "Microphone access is blocked. Please enable it in Settings.",
allowText = "Allow",
openSettingsText = "Open Settings",
dismissText = "Not now",
onError = { e ->
// Mic busy (another app recording), permission revoked, or AudioRecord failed.
// The listener has already sent TuningResult.Silence before calling this.
},
onResult = { result ->
//...your code here
}
)@Composable
fun PitchKitDemo() {
var resultNote by remember { mutableStateOf("-") }
var resultFreq by remember { mutableDoubleStateOf(0.0) }
// ==========================================
// 1. Start the tuner
// ==========================================
PitchKitListener(profile = InstrumentProfile.Guitar) { result ->
when (result) {
is TuningResult.Note -> resultFreq = result.freq.toDouble()
else -> resultFreq = 0.0 // clear freq on chord/silence
}
resultNote = when (result) {
is TuningResult.Note -> result.name
is TuningResult.Chord -> result.name
TuningResult.Silence -> "-"
}
}
// ==========================================
// 2. Render your UI
// ==========================================
Column(horizontalAlignment = Alignment.CenterHorizontally) {
Text(text = resultNote)
if (resultFreq > 0) {
Text(text = "${"%.1f".format(resultFreq)} Hz")
}
}
}Each of the 12 roots is combined with the following qualities:
major, minor (m), dominant 7th (7), minor 7th (m7), major 7th
(maj7), sus2, sus4, diminished (dim), and augmented (aug).
Examples: C, Am, G7, Em7, Dmaj7, Asus2, Bdim, Faug.
If you enjoy this project, please give it a star! Check out all the stargazers here: Stargazers on GitHub
This library is actively maintained. Feedback, bug reports, and feature requests are welcome! Please feel free to open an issue or submit a pull request.
