Last active
April 4, 2020 14:49
-
-
Save kirkegaard/9e23632902a1a76d0ee4ad20e6403714 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
import struct | |
import wave | |
import sys | |
w = wave.open(sys.argv[1], 'rb') | |
sum = 0 | |
value = 0; | |
delta = 0; | |
amps = [] | |
for i in range(0, w.getnframes()): | |
# Assume stereo, mix the channels. | |
data = struct.unpack('<hh', w.readframes(1)) | |
sum += (data[0] * data[0] + data[1] * data[1]) / 2 | |
# 44100 / 30 = 1470 | |
if (i != 0 and (i % 1470) == 0): | |
value = int(math.sqrt(sum / 1470.0) / 10) | |
amps.append(value - delta) | |
delta = value | |
sum = 0 | |
print(amps) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment