Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # https://stackoverflow.com/questions/13243690/decibel-values-at-specific-points-in-wav-file/13244011#13244011
- import scipy.io.wavfile
- import numpy as np
- import matplotlib.pyplot as plt
- import sys, argparse, os, os.path
- parser = argparse.ArgumentParser('plot the dB level of a .WAV file')
- parser.add_argument('wav_file')
- cmdline = parser.parse_args()
- samprate, wavdata = scipy.io.wavfile.read(cmdline.wav_file)
- numchunks = len(wavdata)/10
- chunks = np.array_split(wavdata.astype(np.int64), numchunks)
- ref_level = (1 << 15)-1 # 16-bit (signed) PCM
- dbs = [20*np.log10( max(np.sqrt(np.mean(chunk**2)),.0001) / ref_level ) for chunk in chunks]
- total_time_sec = len(wavdata) / samprate
- t = np.linspace(0,total_time_sec,len(wavdata)/10)
- plt.plot(t,dbs,'k-')
- plt.title(os.path.basename(cmdline.wav_file))
- plt.grid(True)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement