flutter_detect_pitch 0.0.1%2B1

SDKflutter
Platformandroidios

A Flutter plugin for real-time pitch detection using the device microphone with native audio processing for iOS and Android.

[# flutter_detect_pitch

A Flutter plugin for real-time pitch detection using the device microphone (iOS and Android).
It uses AVAudioEngine and Accelerate (iOS) or AudioRecord (Android) for fast and reliable frequency estimation.


🚀 Features

  • 🎤 Real-time microphone input
  • ⚙️ Native audio processing (AVAudioEngine on iOS, AudioRecord on Android)
  • 📡 Pitch detection via FFT (iOS) or zero-crossing (Android)
  • 📶 Stream interface for live frequency values
  • 🔒 Works offline and privacy-friendly

Platform Support: iOS ✅, Android ✅


📦 Installation

Add to your pubspec.yaml:

dependencies:
  flutter_detect_pitch: ^0.0.1+1

Then run:

flutter pub get

⚙️ iOS Configuration

Add this to your Info.plist:

<key>NSMicrophoneUsageDescription</key>
<string>This app uses the microphone to detect pitch.</string>

⚙️ Android Configuration

Add this permission to your android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.RECORD_AUDIO"/>

Make sure your minSdkVersion is 21 or higher in android/app/build.gradle:

defaultConfig {
    minSdk = 21
}

For Android 6.0+ you must also request runtime permission using e.g. the permission_handler plugin.


💡 Usage

import 'package:flutter_detect_pitch/flutter_detect_pitch.dart';

void startListening() async {
  // Request permission if needed
  if (await Permission.microphone.request().isGranted) {
    PitchDetector.pitchStream.listen((frequency) {
      print('Detected frequency: ${frequency.toStringAsFixed(2)} Hz');
    });
  }
}

You can start this from a button or widget lifecycle like initState.


🔁 API

PitchDetector.pitchStream

A broadcast stream that emits a new frequency value (as double) every ~100ms.


📱 Example

A simple example is available under example/. To run it:

cd example
flutter run

📋 Roadmap

  • iOS pitch detection via FFT
  • Android pitch detection via AudioRecord
  • Frequency → musical note conversion
  • Visual pitch indicator widget
  • Replace Android zero-crossing with FFT or Yin

🧪 Known Limitations

  • Android detection is basic (zero-crossing only)
  • Background noise can impact accuracy
  • Outputs raw frequency only (not musical notes)

📄 License

MIT License. See LICENSE.


👤 Author

Developed by Felix L – feel free to contribute or open issues!

GitHub: https://github.com/felix-ml/pitch_detector ]()