def insert_file(fn, word):
	"""
	Read the signal in file fn, calculate the fingerprints and 
	insert them into database.
	"""
	X, params = readWaveFile(fn, withParams=True)

	fingerprints = get_fingerprints(X, sr=params[2])

	db = Database()
	db.insert(word, fingerprints)
	db.logout()
def recognize_file(fn):
	"""
	Recognize the given audio file fn.
	"""
	X, params = readWaveFile(fn, withParams=True)

	fingerprints = get_fingerprints(X, sr=params[2])

	db = Database()
	word = db.find(fingerprints)
	db.logout()

	if word:
		print(fn + " is about word \"" + word + "\"")
	else:
		print("Cannot recognize file " + fn + ".")
Beispiel #3
0
def getFingerPrint(path, start=None, end=None):
	print("Creating fingerprint of ",path)
	X = au.readWaveFile(path)
	if start != None:
		if end != None:
			X = X[(SR*start):(SR*end)]
	l = len(X)
	i = 0
	fp = []
	while i <= (l - 4096): 
		P = realFFT(X[i:(i+WINDOW_SIZE)])
		p = pickPeaks(P)
		# print(p)
		fp.append(sorted(p))
		# au.graphSpectrum(X[i:(i+WINDOW_SIZE)])
		i += SLIDE_INTERVAL

	print("Generated", len(fp), "windows.")
	return fp
Beispiel #4
0
import numpy as np
import audioUtilities as au

signal = au.readWaveFile("SteelString.wav")
# au.displaySignal(signal)
# print(len(signal))
amp_envelope = au.getEnvelope(signal, 2205, 2205)
# au.displaySignal(amp_envelope)

# # print(amp_envelope)
signal = signal[:44100]

# tx = [ 5 , 6, 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ]
tx = signal
ta = [0.5, 0.7]

intermediateWindows = []
window = len(ta)


def zeroPadLeft(lst, m):
    for j in range(m):
        lst.insert(j, 0)
    return lst


for i in range(0, len(tx) - 1, 2):
    for j in range(len(ta)):
        intermediateWindows.append(ta[j] * tx[i])

q = [
Beispiel #5
0
def getMaxAmp_Wave(filename):
    wave = au.readWaveFile(filename)
    maxAmp = max(wave)
    return (maxAmp, wave)
Beispiel #6
0
    if value < 0:
        final = value + new_amp
    else:
        final = value - new_amp
    return final

def compress_wav(filename, threshLimit, ratio):
    (_sourceMax, _sourceWave)  = getMaxAmp_Wave(filename)
    threshold = int(_sourceMax / threshLimit)
    _new = []
    for elem in _sourceWave:
        if abs(elem) > threshold:
            # use decibel reduce function to find new amp add to list
            diff = threshold - elem
            dr = decibelReduce(elem, diff, ratio)
            _new.append(dr)
        else:
            _new.append(elem)
    return _new


test = au.readWaveFile("Bn.wav")
test_compress = compress_wav("Bn.wav", 2, 2)
#
au.displaySignal(test)
au.displaySignal(test_compress)
# au.writeWaveFile("BnNew2.wav", test_compress)


#
Beispiel #7
0
def main(file, displaySignal=False):
	filename = file.split(".wav")[0]
	wave = au.readWaveFile(file)
	if(displaySignal):
		displaySignals(wave)
	writeAudioFilters(wave, filename)
Beispiel #8
0
def main(file, displaySignal=False):
    filename = file.split(".wav")[0]
    wave = au.readWaveFile(file)
    if (displaySignal):
        displaySignals(wave)
    writeAudioFilters(wave, filename)
Beispiel #9
0
        s1 = [np.float64(i.real) for i in s1]
        s1 = np.asarray(s1)
        s2 = np.fft.fft(hanning_window * a2)
        s2 = [np.float64(i.real) for i in s2]
        s2 = np.asarray(s2)
        phase = (phase + np.angle(s2 / s1)) % 2 * np.pi
        a2_rephased = np.fft.ifft(np.abs(s2) * np.exp(1j * phase))
        a2_rephased = [np.float64(i.real) for i in a2_rephased]

        # add to result
        i2 = int(i / f)
        result[i2:i2 + window_size] += hanning_window * a2_rephased

    result = ((2**(16 - 4)) * result / result.max())  # normalize (16bit)

    return result.astype('int16')


ninth = au.readWaveFile("Beethoven.Ninth.wav")
window_size = 2**13
h = 2**11
n = 10
factor = 2**(1.0 * n / 12.0)
test = stretch(ninth, 1 / factor, window_size, h)
# test = stretch(ninth, 1, 2048, 1024)
# slower = stretch(ninth, 0.5, 2048, 512)
# faster = stretch(ninth, 1.5, 2048, 512)
au.writeWaveFile("BeethovenNinth10.wav", test)
# au.writeWaveFile("BeethovenNinthHalf.wav", slower)
# au.writeWaveFile("BeethovenNinthOneAndAHalf.wav", faster)
Beispiel #10
0
import audioUtilities as au

# SR = 44100
# maxAmp = 2**15 -1

# def exponentialDecay(i,h):
#     return 2**(-i/(SR*h)) 

# amps = [i/SR for i in range(SR)], [exponentialDecay(i,0.6) for i in range(SR)][1] 

# bach = au.readWaveFile("Bach.wav")

# def reverb(amps, X):
# 	for i in range(len(amps)-1,len(X)):
# 		for j in range(len(amps)):
# 			out[i] += amps[j]*X[i-j]
# 	return out

# print(reverb(amps,bach))

signal = au.readWaveFile("BassGuitar.wav")
impulse = au.readWaveFile("ConcertHall.wav")

# print(len(impulse), len(signal))

# convolved = np.convolve(signal,impulse)
# print(convolved[0:100])

au.writeWaveFile("BassConcert.wav", np.convolve(signal,impulse,'valid'))

Beispiel #11
0
        s1 = [np.float64(i.real) for i in s1]
        s1 = np.asarray(s1)
        s2 =  np.fft.fft(hanning_window * a2)
        s2 = [np.float64(i.real) for i in s2]
        s2 = np.asarray(s2)
        phase = (phase + np.angle(s2/s1)) % 2*np.pi
        a2_rephased = np.fft.ifft(np.abs(s2)*np.exp(1j*phase))
        a2_rephased = [np.float64(i.real) for i in a2_rephased]

        # add to result
        i2 = int(i/f)
        result[i2 : i2 + window_size] += hanning_window*a2_rephased

    result = ((2**(16-4)) * result/result.max()) # normalize (16bit)

    return result.astype('int16')

ninth = au.readWaveFile("Beethoven.Ninth.wav")
window_size = 2**13
h = 2**11
n = 10
factor = 2**(1.0*n/12.0)
test = stretch(ninth, 1/factor, window_size, h)
# test = stretch(ninth, 1, 2048, 1024)
# slower = stretch(ninth, 0.5, 2048, 512)
# faster = stretch(ninth, 1.5, 2048, 512)
au.writeWaveFile("BeethovenNinth10.wav", test)
# au.writeWaveFile("BeethovenNinthHalf.wav", slower)
# au.writeWaveFile("BeethovenNinthOneAndAHalf.wav", faster)

Beispiel #12
0
import numpy as np
import audioUtilities as au

signal = au.readWaveFile("SteelString.wav")
# au.displaySignal(signal)
# print(len(signal))
amp_envelope = au.getEnvelope(signal, 2205, 2205)
# au.displaySignal(amp_envelope)

# # print(amp_envelope)
signal = signal[:44100]

# tx = [ 5 , 6, 7 , 8 , 9 , 10 , 11 , 12 , 13 , 14 ]
tx = signal
ta = [ 0.5 , 0.7 ]

intermediateWindows = []
window = len(ta)

def zeroPadLeft(lst,m):
    for j in range(m):
        lst.insert(j, 0)
    return lst

for i in range(0, len(tx) - 1, 2):
    for j in range(len(ta)):
        intermediateWindows.append(ta[j] * tx[i])

q = [intermediateWindows[i:i+window] for i  in range(0, len(intermediateWindows), window)]
z = []