ffthealthdev 1.0.2+19 copy "ffthealthdev: ^1.0.2+19" to clipboard
ffthealthdev: ^1.0.2+19 copied to clipboard

outdated

Pitch detection plugin, made for my personal project. Makes use of platform channels (currently Android only) in order to process audio in real-time and give feedback.

example/lib/main.dart

import 'package:ffthealthdev/ffthealthdev.dart';
import 'package:flutter/material.dart';

void main() => runApp(Application());

class Application extends StatefulWidget {
  @override
  ApplicationState createState() => ApplicationState();
}

class ApplicationState extends State<Application> {
  double? frequency;
  String? note;
  int? octave;
  bool? isRecording;

  FftHealthdev fftHealthdev = new FftHealthdev();

  _initialize() async {
    print("Starting recorder...");
    // print("Before");
    // bool hasPermission = await fftHealthdev.checkPermission();
    // print("After: " + hasPermission.toString());

    // Keep asking for mic permission until accepted
    while (!(await fftHealthdev.checkPermission())) {
      fftHealthdev.requestPermission();
      // IF DENY QUIT PROGRAM
    }

    // await fftHealthdev.checkPermissions();
    await fftHealthdev.startRecorder();
    print("Recorder started...");
    setState(() => isRecording = fftHealthdev.getIsRecording);

    fftHealthdev.onRecorderStateChanged.listen(
        (data) => {
              print("Changed state, received: $data"),
              setState(
                () => {
                  frequency = data[1] as double,
                  note = data[2] as String,
                  octave = data[5] as int,
                },
              ),
              fftHealthdev.setNote = note!,
              fftHealthdev.setFrequency = frequency!,
              fftHealthdev.setOctave = octave!,
              print("Octave: ${octave!.toString()}")
            },
        onError: (err) {
          print("Error: $err");
        },
        onDone: () => {print("Isdone")});
  }

  @override
  void initState() {
    isRecording = fftHealthdev.getIsRecording;
    frequency = fftHealthdev.getFrequency;
    note = fftHealthdev.getNote;
    octave = fftHealthdev.getOctave;
    super.initState();
    _initialize();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        title: "Simple flutter fft example",
        theme: ThemeData.dark(),
        color: Colors.blue,
        home: Scaffold(
          backgroundColor: Colors.purple,
          body: Center(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                isRecording!
                    ? Text("Current note: ${note!},${octave!.toString()}",
                        style: TextStyle(fontSize: 30))
                    : Text("Not Recording", style: TextStyle(fontSize: 35)),
                isRecording!
                    ? Text(
                        "Current frequency: ${frequency!.toStringAsFixed(2)}",
                        style: TextStyle(fontSize: 30))
                    : Text("Not Recording", style: TextStyle(fontSize: 35))
              ],
            ),
          ),
        ));
  }
}
0
likes
0
points
1
downloads

Publisher

unverified uploader

Weekly Downloads

Pitch detection plugin, made for my personal project. Makes use of platform channels (currently Android only) in order to process audio in real-time and give feedback.

Homepage

License

unknown (license)

Dependencies

flutter

More

Packages that depend on ffthealthdev

Packages that implement ffthealthdev