0

Trying to normalize the volume for 1000's of small mp3 files. For this, I am looking for a way to get the RMS of each audio file:

var ThisRMS;
$('audio').attr('src','xxx.mp3');
ThisRMS=$('audio').rms;  //***This functionality is what I'm looking for****
$('audio').prop('volume',1/ThisRMS); //Set louder for low RMS
$('audio')[0].play(); 

Any help with this missing audio "RMS" function would be much appreciated.

Cymro
  • 1,201
  • 1
  • 11
  • 29
  • Square every sample, take the mean, square root the result? – fdcpp Jan 20 '20 at 20:55
  • And how would you go about getting each sample fdcpp? – Cymro Jan 21 '20 at 21:36
  • Now, that’s your real question, or at least part of the underlying one. Server side or client side? – fdcpp Jan 22 '20 at 08:49
  • Also, which audio codec? `mp3`, `wav`, `aiff`, all of the above? As a follow-up question will likely be _how do I decode an audio file on the server / client side with javascript_ – fdcpp Jan 22 '20 at 11:18
  • Hi fdcpp. My question says 'jQuery' which is client side. But if you have a solution for server side (PHP), by all means, great! As shown in the code, the files are all mp3. – Cymro Jan 22 '20 at 17:29
  • To get a good response from relative communities it may be worthwhile rephrasing this question. That said, here is an SO question to save you searching. [How to read and write into file using JavaScript?](https://stackoverflow.com/a/586984/8876321) _For completeness, the OP does not state he is looking to do this in a browser (if he is, as has been stated, it is generally not possible)_. So that puts you at server side only. [*PHP:* read file](https://www.w3schools.com/php/php_file_open.asp), [Node: read file](https://nodejs.org/dist/latest-v6.x/docs/api/fs.html) – fdcpp Jan 22 '20 at 19:59
  • Next you might want to look at existing libraries. FFMPEG may be a good start [php](https://trac.ffmpeg.org/wiki/PHP), [node](https://www.npmjs.com/package/ffmpeg). RMS is not useful measure when applied over a longe period, bt rather is applicable over short snapshots of audio, [see this SO answer](https://superuser.com/a/1184012) – fdcpp Jan 22 '20 at 20:02

0 Answers0