Created
June 21, 2016 08:29
-
-
Save RicherMans/99cd0711983ec6bc02d1997c3a18a82f to your computer and use it in GitHub Desktop.
Just plots a wave and its fft
This file contains hidden or 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 matplotlib.pyplot as plt | |
import numpy as np | |
import wave | |
import sys | |
import scipy.fftpack | |
import os | |
import argparse | |
def parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('f',type=str) | |
return parser.parse_args() | |
args = parse_args() | |
spf = wave.open(args.f,'r') | |
fname = os.path.basename(args.f) | |
bname,_ = os.path.splitext(fname) | |
#Extract Raw Audio from Wav File | |
signal = spf.readframes(-1) | |
signal = np.fromstring(signal, 'Int16') | |
yf = scipy.fftpack.fft(signal) | |
#If Stereo | |
if spf.getnchannels() == 2: | |
print 'Just mono files' | |
sys.exit(0) | |
fig, ax = plt.subplots() | |
fig.patch.set_visible(False) | |
ax.axis('off') | |
ax.plot(signal) | |
fig.savefig(bname+'.png') | |
fig, ax = plt.subplots() | |
fig.patch.set_visible(False) | |
ax.axis('off') | |
ax.plot(yf[0:signal.shape[0]/2]) | |
fig.savefig(bname+'fft.png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment