Search code examples
flutteraudiotflite

MissingPluginException using TensorFlow Lite audio classifier on Flutter


I am trying to use a TensorFlow Lite audio classifier (made with Teachable Machine) on Flutter but when recognition starts I get this exception:

MissingPluginException(No implementation found for method listen on channel FileRecognitionStream)

Here is the code where recognition starts:

Future<void> stopRecording() async {
    try {
      String? path = await recorder.stop();
      setState(() {
        isListening = false;
        recordingPath = path!;
        recognitionStream = TfliteAudio.startFileRecognition(
          sampleRate: 44100,
          audioDirectory: recordingPath,
        );
        recognitionStream.listen((event) {
          recognition = event["inferenceTime"];
          inferenceTime = event["recognitionResult"];
        }).onDone(() {
           print("DONE");
        });
      });
    } catch (e) {
      print('Error Start Recording: $e');
    }
  }

When the recording stops, a file is created and its path is fed to the classifier. I run the application on web, when the recording starts, I allow chrome to use microphone and as soon as it stops recording I get the exception.


Solution

  • MissingPluginException means that the code you are using cannot run on your targeted platform. In your case, I guess you are using tflite_audio package: https://pub.dev/packages/tflite_audio and you try to run your code on web. But according to the above link, the package is meant to run on Android and IOS only. That's why you get the error.

    To solve your problem, you have to look for another package that supports the web platform, or to create your own tool yourself. You can browse some interesting audio packages here: https://fluttergems.dev/audio/