# Extract power levels of mp3 sound at given times?

Consider loading an mp3 audio file

mymp3=Import["test.mp3"];


Now we get an object that looks like

One can see a picture of the sound fluctuations, which means that Mathematica knows how to access the raw values of the wave. Now, I would like to take small bits of the waveform at certain times (let's say, from second 40.0 to second 40.3), sum up its absolute value squared and divide by the time length to get the power of the signal at this time. Can I do this in Mathematica?

In version 11.1, you can use AudioLoudness. It can use several loudness definitions. I am not familiar with these, but you can look them up.

au = ExampleData[{"Audio", "Clapping"}]

AudioLoudness[au] // ListLinePlot


To compute precisely what you are describing in version 11.0 or later, use AudioBlockMap.

AudioBlockMap[Norm, au, Quantity[0.1, "Seconds"]] // ListLinePlot


To get the plot you showed in your screenshot, use AudioPlot[au].

• This looks good, but what if I want to end up with a table of loudness? Each entry in the table should correspond to the average loudness within 0.3 consecutive seconds in the mp3 audio. – Kagaratsch Mar 25 '17 at 19:54
• @Kagaratsch You get a TimeSeries from these functions, you can convert it with Normal. Normal@AudioBlockMap[Norm, au, Quantity[0.3, "Seconds"]]. – Szabolcs Mar 25 '17 at 19:55
• The waveform is stored in the second argument of a RawData object, which is in the first argument of the Audio object we get upon Import of the file. I wanted to access these by taking parts of the Audio object, or isolate the waveform by substitution rules, but nothing seems to work. It is as if the head Audio is protected against any manipulations. Just out of curiosity, is there a way to extract the List with raw waveform information from the Audio object somehow? – Kagaratsch Mar 25 '17 at 20:00
• @Kagaratsch Audio objects are atomic and their internal structure shouldn't be messed with. You can get the data with AudioData. It's an analogue of ImageData. Many other audio functions are named similarly to image processing ones. You can also do direct arithmetic on Audio objects without extracting their contents, like Total[#^2] & /@ AudioPartition[au, 0.3] – Szabolcs Mar 25 '17 at 20:06
• @Kagaratsch, then that would just be RootMeanSquare[#]^2 &. – J. M.'s discontentment Mar 26 '17 at 3:19