cvt2PCM function

void cvt2PCM(
  1. String inputPath,
  2. String outputPath, {
  3. String? logPath,
})

Implementation

void cvt2PCM(String inputPath, String outputPath, {String? logPath}) {
  Map<String, String> option;
  if (logPath == null) {
    option = {
      "terminal": "yes",
      "gapless-audio": "yes",
      "o": outputPath,
      "of": "s16le",
      "oac": "pcm_s16le",
      "audio-channels": "1",
      "audio-samplerate": "16000"
    };
  } else {
    option = {
      "terminal": "yes",
      "gapless-audio": "yes",
      "log-file": logPath,
      "o": outputPath,
      "of": "s16le",
      "oac": "pcm_s16le",
      "audio-channels": "1",
      "audio-samplerate": "16000"
    };
  }
  mpv.Player player = mpv.Player(option);

  player.command(["loadfile", inputPath]);

  while (true) {
    Pointer<mpv_event> event = player.waitEvent(0);
    if (event.ref.event_id == mpv_event_id.MPV_EVENT_SHUTDOWN) {
      break;
    } else if (event.ref.event_id == mpv_event_id.MPV_EVENT_END_FILE) {
      break;
    }
  }
  player.destroy();

  print("Generated PCM file at: $outputPath");
}