from numpy import * import matplotlib.pyplot as plot import WAV as wav from VAD import vad import scipy # Load sample input x, sr = wav.read("wav/test/test_bh_raw.wav") # Set VAD parameters winSize = int(sr*20e-3) # in samples (fs*s) hopSize = winSize # in samples smoothingGain = [0.3, 0.02] # small numbers TODO: calculte for 0-values 0.1, 0.2, 0.3 triggerThresholds = [-25, -20] # in dBFS # Estimate silent frames vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds) # Plot results plot.figure() plot.plot(x, "b") #plot.plot(range(0, len(x)-winSize, hopSize), vadFlags*max(x), "r") plot.plot(range(0, len(x)-winSize, hopSize), vadFlags[:,1], "r", linewidth=2) # TEST plot.plot(range(0, len(x)-winSize, hopSize), vadFlags[:,2], "b") plot.plot(range(len(x)), triggerThresholds[0]*ones(len(x)), "g--") plot.plot(range(len(x)), triggerThresholds[1]*ones(len(x)), "g--") plot.show()
from numpy import * import matplotlib.pyplot as plot import WAV as wav from VAD import vad import scipy # Load sample input x, sr = wav.read("wav/test/test_bh_raw.wav") # Set VAD parameters winSize = int(sr * 20e-3) # in samples (fs*s) hopSize = winSize # in samples smoothingGain = [0.3, 0.02 ] # small numbers TODO: calculte for 0-values 0.1, 0.2, 0.3 triggerThresholds = [-25, -20] # in dBFS # Estimate silent frames vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds) # Plot results plot.figure() plot.plot(x, "b") #plot.plot(range(0, len(x)-winSize, hopSize), vadFlags*max(x), "r") plot.plot(range(0, len(x) - winSize, hopSize), vadFlags[:, 1], "r", linewidth=2) # TEST plot.plot(range(0, len(x) - winSize, hopSize), vadFlags[:, 2], "b") plot.plot(range(len(x)), triggerThresholds[0] * ones(len(x)), "g--") plot.plot(range(len(x)), triggerThresholds[1] * ones(len(x)), "g--")
from numpy import * import matplotlib.pyplot as plot import WAV as wav from VAD import vad, mute filename = "tomsawyer.wav" # Load sample input x, sr = wav.read("wav/" + filename) # Set VAD parameters winSize = int(sr*20e-3) # in samples (fs*s) hopSize = winSize # in samples smoothingGain = [0.3, 0.02] # small numbers triggerThresholds = [-25, -20] # in dBFS # Estimate silent frames vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds) # Mute silent frames y = mute(x, winSize, hopSize, vadFlags) # Plot results plot.figure() plot.plot(x, "b") plot.plot(y, "r") plot.plot(range(0, len(y)-winSize, hopSize), vadFlags[:,1], "g--") plot.legend(("Input signal", "Output signal", "Signal offset")) plot.show() # Write out results
from numpy import * from Oscillator import * #import matplotlib.pyplot as plot import WAV as wav [input, sr] = wav.read('wav/x1.wav') oscillator = Oscillator(sr, 1000.0) wave = oscillator.getBuffer(len(input)) output = multiply(input, wave) #wav.sound(input, sr, "/tmp/input.wav") wav.sound(output, sr, "/tmp/output.wav")
from numpy import * import WAV as wav from Oscillator import * # Load sample input [x, sr] = wav.read('wav/tomsawyer.wav') # Make cos wave osc = Oscillator(sr, 500.0) f = osc.getBuffer(len(x)) # Shift frequency by f Hz y = multiply(x, f) # Write out results wav.write(x, sr, "wav/freqshift_input.wav") wav.write(y, sr, "wav/freqshift_output.wav")
from numpy import * import matplotlib.pyplot as plot import WAV as wav from VAD import vad, mute filename = "tomsawyer.wav" # Load sample input x, sr = wav.read("wav/" + filename) # Set VAD parameters winSize = int(sr * 20e-3) # in samples (fs*s) hopSize = winSize # in samples smoothingGain = [0.3, 0.001] # small numbers triggerThresholds = [-25, -20] # in dBFS # Estimate silent frames vadFlags = vad(x, winSize, hopSize, smoothingGain, triggerThresholds) # Mute silent frames y = mute(x, winSize, hopSize, vadFlags) # Plot results plot.figure() plot.plot(x, "b") plot.plot(y, "r") plot.plot(range(0, len(y) - winSize + 1, hopSize), vadFlags[:, 1], "g--") plot.legend(("Input signal", "Output signal", "Signal offset")) plot.show() # Write out results
from numpy import * import matplotlib.pyplot as plot import WAV as wav def rotate(array, n=1): n = n % len(array) return array[n:] + array[:n] def rms(array): result = 0 for i in range(len(array)): result += array[i] * array[i] return result # sqrt(result/len(array)) # Input data x = wav.read("samples/test.wav") x = x[0] # Output data y = zeros(len(x)) # Init RMS buffer rmsBufferSize = 10; rmsBuffer = zeros(rmsBufferSize); # Fill output data for i in range(len(x)): rmsBuffer[0] = x[i] y[i] = rms(rmsBuffer) bla = rotate(rmsBuffer)