Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import wave
- import pyaudio
- import numpy as np
- import os, copy
- import math
- from scipy.io.wavfile import write
- from scipy.io.wavfile import read
- from numpy import cos, sin, pi, absolute, arange, log10
- from scipy.signal import kaiserord, lfilter, firwin, freqz, hilbert
- from pylab import figure, clf, plot, xlabel, ylabel, xlim, ylim, title, grid, axes, show, semilogx, xticks
- import numpy as np
- import matplotlib.pyplot as plt
- INT16_FAC = (2**15)-1
- INT32_FAC = (2**31)-1
- INT64_FAC = (2**63)-1
- norm_fact = {'int16':INT16_FAC, 'int32':INT32_FAC, 'int64':INT64_FAC,'float32':1.0,'float64':1.0}
- def wavread(filename):
- (fs, x) = read(filename) # read a sound file and return an array with the sound and the sampling rate
- x = np.float32(x)/norm_fact[x.dtype.name] #scaling down and converting audio into floating point number between range -1 to 1
- return fs, x
- if __name__ == '__main__':
- (fs, xin) = wavread('test.wav')
- if (len(xin.shape) == 1):
- print('Mono files unsupported.')
- exit()
- x = xin[:,0]
- N = len(x)
- env1 = 0.0 # lowpass
- y1 = []
- for n in range(N):
- tmp1 = x[n]
- env1 = 0.95 * (env1 - tmp1) + tmp1
- y1.append (env1)
- H = abs(hilbert(y1)) # module of hilbert transform
- plot(range(N),H)
- show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement