flutter_piano_audio_detection 1.0.5 copy "flutter_piano_audio_detection: ^1.0.5" to clipboard
flutter_piano_audio_detection: ^1.0.5 copied to clipboard

Flutter plug-in for Piano Audio Detection. Can recognize the piano sound in real time using Google Magenta tflite model.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_piano_audio_detection/flutter_piano_audio_detection.dart';
import 'dart:async';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final isRecording = ValueNotifier<bool>(false);
  FlutterPianoAudioDetection fpad = new FlutterPianoAudioDetection();

  Stream<List<dynamic>>? result;
  List<String> notes = [];
  String printText = "";

  @override
  void initState() {
    super.initState();
    fpad.prepare();
  }

  void start() {
    fpad.start();
    getResult();
  }

  void stop() {
    fpad.stop();
  }

  void getResult() {
    result = fpad.startAudioRecognition();
    result!.listen((event) {
      printText = "";
      setState(() {
        notes = fpad.getNotes(event);
      });
      notes.map((e) => {printText += e});
      print(notes);
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Flutter Piano Audio Detection'),
        ),
        body: Center(
          child: Text(
            '${notes}',
            style: TextStyle(fontSize: 72, fontWeight: FontWeight.bold),
          ),
        ),
        floatingActionButton: Container(
          child: ValueListenableBuilder(
            valueListenable: isRecording,
            builder: (context, value, widget) {
              if (value == false) {
                return FloatingActionButton(
                  onPressed: () {
                    isRecording.value = true;
                    start();
                  },
                  backgroundColor: Colors.blue,
                  child: const Icon(Icons.mic),
                );
              } else {
                return FloatingActionButton(
                  onPressed: () {
                    isRecording.value = false;
                    stop();
                  },
                  backgroundColor: Colors.red,
                  child: const Icon(Icons.adjust),
                );
              }
            },
          ),
        ),
      ),
    );
  }
}
37
likes
120
pub points
28%
popularity

Publisher

unverified uploader

Flutter plug-in for Piano Audio Detection. Can recognize the piano sound in real time using Google Magenta tflite model.

Homepage
Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (LICENSE)

Dependencies

flutter, permission_handler

More

Packages that depend on flutter_piano_audio_detection