flutter_sound icon indicating copy to clipboard operation
flutter_sound copied to clipboard

Converting audio to samples

Open MATTYGILO opened this issue 5 years ago • 8 comments

Is there a way that I can convert audio recorded into samples. At the moment the audio files are being saved to the directory /storage/emulated/0/default.m4a. How can I convert the data in this files into samples.

MATTYGILO avatar Aug 01 '19 20:08 MATTYGILO

I am not quite sure if I understood you. What do you exactly mean by the samples instead of files?

hyochan avatar Sep 14 '19 18:09 hyochan

This issue is stale because it has been open 30 days with no activity. Leave a comment or this will be closed in 5 days.

github-actions[bot] avatar Dec 30 '19 00:12 github-actions[bot]

I have the same request. I would like to get the audio data in a buffer. an array of samples [0, 1 , 0.5 .. .. ] I would use this to compute and fft on the live data

honeyspoon avatar Feb 04 '22 15:02 honeyspoon

I shared how I did it in issue #844 but I'll paste it here as well.

Following the 'recordToStream/recordToStreamExample.dart' example, I listen to the StreamController and set the ByteBuffer content of the FoodData to the state for processing.

var recordingDataController = StreamController<Food>();
    _mRecordingDataSubscription =
        recordingDataController.stream.listen((buffer) {
      if (buffer is FoodData) {
        setState(() {
          _data = buffer.data!.buffer;
        });
        sink.add(buffer.data!);
      }
    });
    await _mRecorder!.startRecorder(
      toStream: recordingDataController.sink,
      codec: Codec.pcm16,
      numChannels: 1,
      sampleRate: tSampleRate,
    );
    setState(() {});

As it is a pcm16 buffer, I process it by taking pairs of bytes and reading them as signed 16 bit integers

int nSamples = data.lengthInBytes ~/ 2;
for (var _i =   0; _i < nSamples; _i++) {
      var sample = data.asByteData(_i*2, 2).getInt16(0) / 32768;

    /* Do something with samples */
}

Yi-Jiahe avatar Feb 22 '22 15:02 Yi-Jiahe

We are currently working on a major development. This is project Taudio. We think that the ability to process audio streams is something really important. Something that is not covered by other audio libraries like Just Audio. We definitely want to improve audio streams support.

But actually things are far from perfect in Flutter Sound. The major problem is that Flutter Sound on Web actually does not support audio streams There are several others problems, but one of the main issues is that that the code is not clean. Flutter Sound uses the OS Media Player (AVMediaPlayer on ios) and the OS Media Recorder (AVMediaRecorder on ios) for regular Players and Recorders. But not for Audio Streams! The code is not homogeneous. The code for startPlayer () is completely different of StartPlayerFromStreams().

We are going to create two new Plugins:

  • TaudioWAA will be an implementation of the Web Audio API from W3C for Flutter on Mobiles
  • TaudioPlayer and TaudioRecorder will be a high layer software above TaudioWAA, allowing to define Players from Stream and Recorders to Stream

Please look to the W3C Recommandation : the audio streams are float32 vectors of numbers comprised between -1.0 and +1.0

This is a major development which will give us work during several months. But at the end we are confident that we will have a library much more powerful than the actual Flutter Sound. Just be patient : work is already in progress

Larpoux avatar Feb 22 '22 18:02 Larpoux

Any way to lend a hand? Probably won't be that much of a help, but still.

honeyspoon avatar Feb 23 '22 14:02 honeyspoon

Oh yes! We really need help. This new project will be terrific. But we are not enough contributors. I am the main developer, but I am very slow to progress. Actually I am working on Milestone 0. This milestone is everything about the project launch.

  • setup the repository
  • setup the host which will host our project
  • setup the doc tool so it will be compatible with dartdoc (very important)
  • setup a live host which will run our live examples
  • ...

The roadmap is defined with 12 milestones on github. The milestone #0 is here

If you or someone else want to contribute you can join us on Discord. Everybody are welcome. Even very simple things like telling us what you think about decisions that we make are useful.

Example : I really wanted that TauDio will be under the GPL license. But everybody told me that it was a bad choice. So I gave up and we decided that TauDio will be released under the MPL license, like Flutter Sound.

Please, join us. You will not have to spend much time if you can't. But even your simple presence on Discord can impact the future of this project

Larpoux avatar Feb 23 '22 16:02 Larpoux

This issue is stale because it has been open 90 days with no activity. Leave a comment or this will be closed in 7 days.

github-actions[bot] avatar Dec 25 '23 01:12 github-actions[bot]