Picovoice / flutter-voice-processor

Flutter audio recording plugin designed for real-time speech audio processing
Apache License 2.0
31 stars 6 forks source link

SwiftFlutterVoiceProcessorPlugin Found Nil #9

Closed sean915213 closed 2 years ago

sean915213 commented 2 years ago

Attempting to use picovoice_flutter package results in crash on iOS when attempting to listen for commands. Steps to reproduce:

  1. Launch app and start PicovoiceManager
  2. Attempt speaking command (nothing is recognized- no wakeword or inference)
  3. Relaunch app
  4. App crashes with "flutter_voice_processor/SwiftFlutterVoiceProcessorPlugin.swift:75: Fatal error: Unexpectedly found nil while unwrapping an Optional value"

Reproducible using boilerplate Flutter app. Only need to add sample Picovoice code to the incrementCounter function:

class _MyHomePageState extends State<MyHomePage> {
    int _counter = 0;

    PicovoiceManager? manager;
    bool managerListening = false;

    @override
    void dispose() {
      super.dispose();
      manager?.stop();
    }

    Future<void> _incrementCounter() async {

    manager ??= PicovoiceManager.create(
          "{KEY}",
          "assets/picovoice/picovoice_wake_word.ppn", 
          () => log('HEARD WAKE WORD'), 
          "assets/picovoice/picovoice_play_card.rhn", 
          (inference) => log('HEARD INFERENCE: $inference')
        );
        if (!managerListening) {
          await manager!.start();
          managerListening = true;
          log('START LISTENING');
        } else {
          log('ALREADY LISTENING');
        }

    setState(() {
      // This call to setState tells the Flutter framework that something has
      // changed in this State, which causes it to rerun the build method below
      // so that the display can reflect the updated values. If we changed
      // _counter without calling setState(), then the build method would not be
      // called again, and so nothing would appear to happen.
      _counter++;
    });
}
laves commented 2 years ago

@sean915213 - thanks for the report. We were able to reproduce this and are going to be addressing this in a release that was already scheduled for this week.

laves commented 2 years ago

@sean915213 - this error was addressed in the latest flutter_voice_processor release (1.0.9) and is included in the latest picovoice_flutter release (2.1.6). Let us know if the fix worked for you.

sean915213 commented 2 years ago

@laves This release has resolved my issue. Thanks!