karostudio / flutter_desktop_audio_recorder

BSD 3-Clause "New" or "Revised" License
0 stars 2 forks source link

flutter_desktop_audio_recorder

This is a Flutter package allowing you to record audio for:

Output file type

Usage


  FlutterDesktopAudioRecorder recorder = FlutterDesktopAudioRecorder();

  @override
  void initState() {
    super.initState();

    _hasMicPermission = await recorder.hasMicPermission();

    recorder.permissionGrantedListener = () {
      if (!mounted) return;
      setState(() {
        _hasMicPermission = true;
      });
    };
  }

  Future startRecording() async {
    _fileName = DateTime.now().millisecondsSinceEpoch.toString();
    String path = await Utilities.getVoiceFilePath();
    try {
      return await recorder.start(path: path, fileName: _fileName);
    } on PlatformException catch (e) {
      switch (e.code) {
        case "permissionError":
          recorder.requestMicPermission();
          break;
        default:
      }
      log(e.message ?? "Unhandled error");
    }
  }

  Future stopRecording() async {
    return recorder.stop();
  }

  Future isRecording() async {
    return recorder.isRecording();
  }

macOS Permission

1. Add usage description to plist 
```
<key>NSMicrophoneUsageDescription</key>
<string>Can We Use Your Microphone Please</string>
```