def prepare_data():

	freqs = np.array([264, 297, 330, 352, 396, 440, 495, 528, 594, 660, 704, 792, 880, 990, 1056]) 	#odredjivanje potrebnih frekvencija
	#freqs = np.array(np.exp(np.linspace(np.log(264), np.log(1056), 15)))						

	chunk = 9600  #96000/10 (sample rate je 96000, uzimam deseti deo sekunde)

	T = 0.1 			#samples/fs 9600/96000

	freqs = freqs * T

	round_freqs = np.round(freqs, 0).astype(np.int64)															

	#data = np.array(data)
	#high = np.amax(data)
	#data = data/high
																				#seckanje zvuka od n s, na n zvukova od 1s

	print round_freqs

	timedata = [] 	#sample-ovi, svaki red je 9600 samplova
	#prvi ton
	#fs, data = read(filename, mmap=False)
	fs, data = read('training/training440.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])

	#drugi ton
	fs, data = read('training/training660.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])

	fs, data = read('training/training330.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])

	fs, data = read('training/training990.wav')

	for i in range(0, 3000):
		timedata.append(data[i*chunk:i*chunk+chunk])	

	timedata = np.array(timedata)

	fftdata = []

	for row in timedata:																		#za svaki zvuk se racuna fft
		fftdata.append(calculatefft(fs, row)[0])

	#fftdata = np.array(fftdata)
	#fftdata = fftdata/10000000000

	amps = []	

	for row in fftdata:																			#uzimanje odgovarajucih amplituda za frekvencije
		#amps.append(row[round_freqs])
		amps.append(localmax(row, round_freqs))

	y = []
	for i in range(0, 3000):
		y.append([1, 0, 0, 0])

	for i in range(0, 3000):
		y.append([0, 1, 0, 0])

	for i in range(0, 3000):
		y.append([0, 0, 1, 0])

	for i in range(0, 3000):
		y.append([0, 0, 0, 1])

	x = np.array(amps)
	y = np.array(y)

	return x, y
示例#2
0
test = np.round(test, 0)

#freqs = np.array(np.exp(np.linspace(np.log(264), np.log(1056), 15)))
#round_freqs = np.round(freqs, 0)

ann = create_and_train()

amptest = []

fst, datat = read('test/200test.wav', mmap = False)
datat = datat[0:9600]
testfft = calculatefft(fst, datat)[0]
#testfft = testfft/10000000000

#amptest.append(testfft[test.astype(np.int64)])
amptest.append(localmax(testfft, test.astype(np.int64)))

fst, datat = read('test/330test.wav', mmap = False)
datat = datat[0:9600]
testfft = calculatefft(fst, datat)[0]
#testfft = testfft/10000000000

#amptest.append(testfft[test.astype(np.int64)])
amptest.append(localmax(testfft, test.astype(np.int64)))

fst, datat = read('test/400test.wav', mmap = False)
datat = datat[0:9600]
testfft = calculatefft(fst, datat)[0]
#testfft = testfft/10000000000

#amptest.append(testfft[test.astype(np.int64)])