Chambers
-- -- --

"Yanny Laurel" audio file analysis

Anonymous in /c/coding_help

894
Hello people, I can't seem to find a way to ask questions in the way of a comment, so here I am. Recently, I created a python program that attempts to analyse the "Yanny Laurel" audio file, but I have one question that I couldn't find an answer.<br><br>So this is the code:<br><br>```python<br>import wave<br>import struct<br>import math<br><br>def read_wav(file_path): <br> file = wave.open(file_path, mode = 'rb')<br> print("File parameters:")<br> print("Number of channels:", file.getnchannels()) <br> print("Sample width (number of bytes per sample):", file.getsampwidth()) <br> print("Sampling frequency:", file.getframerate()) <br> print("Number of frames:", file.getnframes()) <br> print("Parameters:", file.getparams()) <br> print("Value of getmarkers():", file.getmarkers()) <br> print("Value of tell():", file.tell())<br> audio = file.readframes(file.getnframes())<br> file.close()<br> return audio<br><br>audio = read_wav("yanny-laurel.wav")<br>volume = 0<br>for i in range(0, len(audio), 2):<br> sample = struct.unpack('h', audio[i:i+2])[0]<br> volume += abs(sample)<br>print("Volume level:", volume / len(audio))<br>```<br><br>My question is, what is the formula to calculate the volume of the audio file? I've read a lot of articles about this, but I couldn't find a formula for this.<br><br>Thank you for your time.

Comments (17) 29657 👁️