flutter_detect_pitch 0.0.1+1
flutter_detect_pitch: ^0.0.1+1 copied to clipboard
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 ]()