Tau: [HELP] Get DBs from sound file

Created on 9 Jun 2020  路  14Comments  路  Source: Canardoux/tau

How to get dbs from sound file to visualize it

enhancement TODO

Most helpful comment

@Larpoux
I solve the problem with FFmpeg command

ffmpeg -i audio.wav -af "aresample=60000,asetnsamples=3000,astats=reset=1:metadata=1,ametadata=print:key='lavfi.astats.Overall.Peak_level':file=status.log" -f null -

you can choose what you want
lavfi.astats.Overall.RMS_level Or lavfi.astats.Overall.Peak_level
https://stackoverflow.com/a/60811629

Or

Decode audio to PCM
https://stackoverflow.com/a/41663511

All 14 comments

Is it something related to #379 ?
Do you want to get this information statically (not during play back) ?

@fzyzcjy, @Mohamed-Fakhry : I think that this feature would be very interesting to implement in Flutter Sound

Yes I can get now will recording only from onRecorderDbPeakChanged
I want to get it from file

I really want this feature in Flutter Sound 馃憤 .
If you work on this feature , I will be interested to have some Pull Request from you.

If you cannot contribute, I will work on that myself. But later (now I am very busy).

I work on it but Do you have an idea about how to make it ?

My idea is to convert your sound to a PCM format if your sound file is with a compressed format like MP3 or OPUS.
You can use FFmpeg (which is embedded inside Flutter sound) to do the conversion.
Probably a WAVE (.wav) file would be convenient. During this process, you must specify a Sample Rate.

Then you can remove the ".wav" header (easy, because this header has a fixed length).

Then you will have an array of Integers 16 bits (if you got a PCM-Linear16 format) or an array of floating point numbers (if you got a PCM-float file format).
Because you know the Sample Rate, it is easy to have correspondence with your timing.

You must process those numbers to get Decibels.

This is my actual idea. But I am not a sound expert, so I am not sure that this would work.
But I would like to work on that 馃憤

@Larpoux
I solve the problem with FFmpeg command

ffmpeg -i audio.wav -af "aresample=60000,asetnsamples=3000,astats=reset=1:metadata=1,ametadata=print:key='lavfi.astats.Overall.Peak_level':file=status.log" -f null -

you can choose what you want
lavfi.astats.Overall.RMS_level Or lavfi.astats.Overall.Peak_level
https://stackoverflow.com/a/60811629

Or

Decode audio to PCM
https://stackoverflow.com/a/41663511

馃 馃憤

Thank you so much 馃槃
FFmpeg is really a great library !

We must implement a Flutter Sound API verb which will use this command.

I get the db as recording values using lavfi.astats.Overall.Peak_level

lavfi.astats.Overall.RMS_level give me different result

Future<List<int>> getPeakLevels(String _pathAudio) async {
    File outputFile = File(
        '/data/user/0/com.flutter.shoutout/cache/1-flutter_sound_example.txt');

    await _flutterFFmpeg
        .execute(
            "-i '$_pathAudio' -af aresample=16000,asetnsamples=16000,astats=reset=1:metadata=1,ametadata=print:key='lavfi.astats.Overall.Peak_level':file=${outputFile.path} -f null -")
        .then((rc) => print("FFmpeg process exited with rc $rc"));

    List<int> wave = List();

    await outputFile
        .openRead()
        .map(utf8.decode)
        .transform(new LineSplitter())
        .forEach((l) {
      if (l.startsWith("frame")) return;
      double value = double.tryParse(l.split("=").last) ?? 0;
      wave.add(70 + value.toInt());
    });

    return wave;
  }

@Larpoux May I make PR ?

Sure 馃憤
If you do now, probably I will be able to put it in next version 5.1.0

Thank you to contribute to Flutter Sound 馃

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.

Dear "bot", please keep this issue open

Dear "bot", please keep this issue open 馃槨

Was this page helpful?
0 / 5 - 0 ratings