Canardoux / flutter_sound

Flutter plugin for sound. Audio recorder and player.
Mozilla Public License 2.0
869 stars 568 forks source link

Converting audio to samples #118

Open MATTYGILO opened 5 years ago

MATTYGILO commented 5 years ago

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.

hyochan commented 5 years ago

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

github-actions[bot] commented 4 years ago

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.

honeyspoon commented 2 years ago

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

Yi-Jiahe commented 2 years ago

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 */
}
Larpoux commented 2 years ago

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:

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

honeyspoon commented 2 years ago

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

Larpoux commented 2 years ago

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.

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

github-actions[bot] commented 9 months ago

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.