Git Product home page Git Product logo

flutter_lame's Introduction

flutter_lame

Flutter native bindings to LAME (MP3 encoder), bundled with LAME source code.

Unlike dart_lame, your don't need to provide prebuilt libraries by yourself. The bundled LAME source code will be built as part of the Flutter Runner build.

Usage

final File f = File("output.mp3");
final IOSink sink = f.openWrite();
final LameMp3Encoder encoder = LameMp3Encoder(sampleRate: 44100, numChannels: 2);


Float64List leftChannelSamples;
Float64List rightChannelSamples;
// Get samples from file or from microphone.

final mp3Frame = await encoder.encode(
  leftChannel: leftChannelSamples,
  rightChannel: rightChannelSamples);
sink.add(mp3Frame);
// continue until all samples have been encoded

// finally, flush encoder buffer
final lastMp3Frame = await encoder.flush();
sink.add(lastMp3Frame);

For a complete example, please go to /example folder.

flutter_lame's People

Contributors

bestowl avatar

Stargazers

 avatar

Watchers

 avatar  avatar

flutter_lame's Issues

iOS环境下,pcm转mp3后,会有哒哒的声音

经过详细的测试发现:
录制的pcm流是正常的,但是经过mp3编码后会出现哒哒的声音。
如果把最初的2800帧流截取掉,就能消除哒哒的杂音。
但是上述的方法会出现新的问题,当播放器初次播放的时候,播放到一半左右的位置就自动暂停了,下一次播放就是正常播放到结束。
上述问题只在iOS环境下出现,Android环境正常。

High memory consumption when the encoder is called.

In my application, I am converting a WAV file to MP3 similarly to the example, but I have noticed a very high growth in memory consumption every time the encoder is initialized.
My app without performing any action consumes 19MB of memory, but every time I initialize the encoder, this memory increases 20MB more.
That is, if I start with a constant consumption of 19MB, when I use the encoder, it increases to 35MB, then 54MB and so on.
Even if I call the garbage collector, the resources that occupy the memory are not released.

Usage:

var encoder = LameMp3Encoder(); //only this line causes the increase in consumption
    IOSink? sink;
      final String outputFilePath = '$defaultPath/$fileName.mp3';
      debugPrint(outputFilePath);

      final wav = await compute(Wav.readFile, inputFile.path);
      wav.toMono();

      final File f = File(outputFilePath);
      sink = f.openWrite();

      encoder = LameMp3Encoder(
          sampleRate: wav.samplesPerSecond,
          numChannels: wav.channels.length,
          bitRate: 30);

      final left = wav.channels[0];
      Float64List? right;
      if (wav.channels.length > 1) {
        right = wav.channels[1];
      }

      //Write file
      for (int i = 0; i < left.length; i += wav.samplesPerSecond) {
        final int endIndex = i + wav.samplesPerSecond;
        final mp3Frame = await encoder.encodeDouble(
          leftChannel:
              left.sublist(i, endIndex < left.length ? endIndex : left.length),
          rightChannel: right?.sublist(
              i, endIndex < right.length ? endIndex : right.length),
        );
        sink.add(mp3Frame);
      }
      sink.add(await encoder.flush());
      await inputFile.delete();
      debugPrint("Finished");
      readyAudioController.sink.add(true);
      recorder.closeRecorder();
      return true;

Namespace not specified

When adding the library as a dependency I get:

A problem occurred configuring project ':flutter_lame'.
Could not create an instance of type com.android.build.api.variant.impl.LibraryVariantBuilderImpl.
Namespace not specified. Specify a namespace in the module's build file: /Users/[username]/.pub-cache/hosted/pub.dev/flutter_lame-1.0.2/android/build.gradle. See https://d.android.com/r/tools/upgrade-assistant/set-namespace for information about setting the namespace.

If you've specified the package attribute in the source AndroidManifest.xml, you can use the AGP Upgrade Assistant to migrate to the namespace value in the build file. Refer to https://d.android.com/r/tools/upgrade-assistant/agp-upgrade-assistant for general information about using the AGP Upgrade Assistant.

I'm on

  • gradle:8.4.1
  • Flutter 3.19.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.