flutter_pitch_detection 1.0.2 copy "flutter_pitch_detection: ^1.0.2" to clipboard
flutter_pitch_detection: ^1.0.2 copied to clipboard

A Flutter plugin for real-time audio pitch detection using TarsosDSP on Android. Provides frequency, note, octave, volume, and accuracy measurements.

Flutter Pitch Detection Plugin #

A Flutter plugin for real-time pitch detection using TarsosDSP on Android.

Features #

  • Real-time pitch detection
  • Frequency, note name, and octave detection
  • Volume measurement (normalized and dBFS)
  • Pitch accuracy and probability
  • Configurable parameters (sample rate, buffer size, etc.)



Installation #

Add to your pubspec.yaml:

dependencies:
  flutter_pitch_detection: ^x.x.x

Then import:

import 'package:flutter_pitch_detection/flutter_pitch_detection.dart';

Quick Start #

Initialize the detector

final pitchDetector = FlutterPitchDetection(); 

Set Parameters (Optional but recommended)

Set individual parameters:

pitchDetector.setSampleRate(44100);  
pitchDetector.setBufferSize(8192);   
pitchDetector.setMinPrecision(0.8);

Or set multiple parameters at once:

pitchDetector.setParameters(toleranceCents: 0.6, bufferSize: 8192, sampleRate: 44100, minPrecision: 0.7);

Start Detection

await pitchDetector.startDetection();

Retrieve Recording Status

await pitchDetector.isRecording();

Listen to Real-Time Updates

StreamSubscription<Map<String, dynamic>>? _pitchSubscription;

_pitchSubscription = FlutterPitchDetectionPlatform.instance.onPitchDetected.listen((event) async {
    await pitchDetector.getNote();
    await pitchDetector.getFrequency();
    await pitchDetector.printNoteOctave();
    await pitchDetector.getOctave();
    await pitchDetector.getToleranceCents();
    await pitchDetector.getBufferSize();
    await pitchDetector.getSampleRate();
    await pitchDetector.isRecording();
    await pitchDetector.getMinPrecision();
    await pitchDetector.getAccuracy(toleranceCents);
    await pitchDetector.isOnPitch(toleranceCents, minPrecision);
    await pitchDetector.getVolume();
    await pitchDetector.getVolumeFromDbFS();
});    

Stop Detection

await pitchDetector.stopDetection();
_pitchSubscription?.cancel();

Method Reference #

Core Methods

  • startDetection({int? sampleRate, int? bufferSize, int? overlap,}) Starts real-time pitch detection. Callback returns (frequency, note, octave, accuracy, volume).
  • stopDetection() Stops the detection.

Configuration (Call before startDetection)

  • setSampleRate(int rate) Sets audio sample rate (e.g., 44100).

  • setBufferSize(int size) Sets buffer size (min 7056).

  • setMinPrecision(double precision) Sets minimum pitch confidence threshold (0.0 to 1.0).

  • setToleranceCents(int cents) Sets pitch tolerance in cents (0.0 to 1.0).

  • getSampleRate() Returns current sample rate.

  • getBufferSize() Returns current buffer size.

  • getMinPrecision() Returns current min precision.

  • getToleranceCents() Returns current tolerance.

Real-Time Data

  • onPitchDetected A real-time event stream that provides continuous pitch detection updates. Subscribe to this stream to receive live audio analysis data, including frequency, note, volume, and accuracy metrics.

  • getFrequency() Returns current detected frequency (Hz).
  • getNote() Returns musical note (e.g., "C").
  • getOctave() Returns note octave (e.g., 4).
  • printNoteOctave() Logs note+octave (e.g., "C4").
  • isOnPitch() Returns bool if pitch meets precision.
  • getAccuracy() Returns pitch confidence in % (0 to 100).
  • getVolume() Returns normalized volume (0.0 to 100.0).
  • getVolumeFromDbFS() Returns volume in dBFS (0.0 to 100.0).
  • isRecording() Returns bool if detection is active.

Important Notes #

  • Android-only: This plugin does not support iOS yet.
  • Parameter Order: Set configs (setSampleRate, setBufferSize, etc.) before startDetection.
  • Permissions: Mic permissions are automatically handled on Android.

Example App #

Check the example/ folder for a complete demo app.

License #

MIT

4
likes
0
points
73
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter plugin for real-time audio pitch detection using TarsosDSP on Android. Provides frequency, note, octave, volume, and accuracy measurements.

Repository (GitHub)
View/report issues

Documentation

Documentation

License

unknown (license)

Dependencies

flutter, permission_handler, plugin_platform_interface

More

Packages that depend on flutter_pitch_detection

Packages that implement flutter_pitch_detection