Skip to content

Commit 67378ad

Browse files
committed
more upload
1 parent 99a13b2 commit 67378ad

File tree

6 files changed

+137
-13
lines changed

6 files changed

+137
-13
lines changed

Data Processing/generate.py

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
"""
2+
Script for linking to MATLAB to generate
3+
an HRTF dataset.
4+
"""
5+
6+
import matlab.engine
7+
import itertools
8+
import os
9+
import random
10+
import time
11+
12+
root = "/Users/ghunk/Desktop/GRADUATE/CSC_464/Final_Project/Dataset/"
13+
14+
paths = {"tools": root + "tools/LISTEN/",
15+
"timit": root + "voice_data/TIMIT_wav/TIMIT_all/",
16+
"hrir": root + "hrtf_data/LISTEN_HRIR/",
17+
"save": root + "binaural_random/"}
18+
19+
elevations = [-45, -30, -15, 0, 15, 30, 45]
20+
azimuths = [15*x for x in range(24)]
21+
combos = list(itertools.product(elevations, azimuths))
22+
23+
def main():
24+
eng = matlab.engine.connect_matlab()
25+
eng.addpath(paths["tools"], nargout=0)
26+
subjects = os.listdir(paths["hrir"])
27+
speakers = os.listdir(paths["timit"])
28+
29+
NUM_RECORDINGS = 100000
30+
31+
# start timer
32+
start_time = time.time()
33+
34+
for i in range(NUM_RECORDINGS):
35+
subject = random.choice(subjects)
36+
speaker = random.choice(speakers)
37+
elev_az = random.choice(combos)
38+
filename = (subject.split("_")[1] + "_" + speaker[:-4] +
39+
"_" + str(elev_az[0]) + "_" + str(elev_az[1]) + ".wav")
40+
eng.greg_synthesize(
41+
(paths["hrir"] + subject),
42+
(paths["timit"] + speaker),
43+
elev_az[0],
44+
elev_az[1],
45+
(paths["save"] + filename),
46+
nargout=0)
47+
48+
# stop timer
49+
elapsed = time.time() - start_time
50+
m, s = divmod(elapsed, 60)
51+
h, m = divmod(m, 60)
52+
print "Time elapsed: ", elapsed
53+
print "Average time: ", elapsed / float(NUM_RECORDINGS)
54+
print "Formatted: %d:%02d:%02d" % (h, m, s)
55+
56+
main()

Data Processing/preprocessing.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
"""
2+
Pre-processing script to transform WAV into STFT
3+
for input into the CNN pipeline.
4+
"""
5+
6+
from scipy import signal
7+
from scipy.io import wavfile
8+
import numpy
9+
import time
10+
import os
11+
12+
def preprocess(filepath):
13+
# CONSTANTS
14+
WINDOW_LENGTH = 0.025
15+
HOP_SIZE = 0.015
16+
# read file, split into L-R, downsample, split into chunks 20 sample chunks
17+
sample_rate, samples = wavfile.read(filepath)
18+
samples_L = samples[:, 0]
19+
samples_R = samples[:, 1]
20+
# compute mag and phase spectrograms
21+
nperseg = int(WINDOW_LENGTH / (1.0 / sample_rate))
22+
noverlap = int(HOP_SIZE / (1.0 / sample_rate))
23+
frequencies_L, times_L, spectogram_L = signal.spectrogram(samples_L, sample_rate, nperseg=nperseg, noverlap=noverlap, window="hamming", mode="complex")
24+
frequencies_R, times_R, spectogram_R = signal.spectrogram(samples_R, sample_rate, nperseg=nperseg, noverlap=noverlap, window="hamming", mode="complex")
25+
mag_spectrogram_L = numpy.absolute(spectogram_L)
26+
mag_spectrogram_R = numpy.absolute(spectogram_R)
27+
phase_spectrogram_L = numpy.angle(spectogram_L)
28+
phase_spectrogram_R = numpy.angle(spectogram_R)
29+
# return tensor
30+
spectrograms_combined = numpy.concatenate((mag_spectrogram_L, phase_spectrogram_L, mag_spectrogram_R, phase_spectrogram_R), axis=0)
31+
spectrograms_combined = spectrograms_combined.astype("float16")
32+
return spectrograms_combined
33+
34+
recording_root = "/Users/ghunk/Desktop/GRADUATE/CSC_464/Final_Project/Dataset/binaural_random/"
35+
save_root = "/Users/ghunk/Desktop/GRADUATE/CSC_464/Final_Project/Dataset/stft/"
36+
37+
def main():
38+
start_time = time.time()
39+
for i, recording in enumerate(os.listdir(recording_root)):
40+
stft = preprocess(recording_root + recording)
41+
filename = save_root + recording.split('.')[0]
42+
numpy.save(filename, stft)
43+
if ((i+1) % 100 == 0):
44+
current_time = time.time() - start_time
45+
print "Time elapsed:", current_time
46+
print "Time per record:", current_time / (i+1)
47+
print i+1, "records saved."
48+
print "Finished."
49+
print "Time elapsed:", time.time() - start_time
50+
51+
main()
52+

LICENSE.txt

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2017 Gregory D. Hunkins
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
File renamed without changes.

neuralnet.py Neural Net/neuralnet.py

+1-12
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
Main Neural Network Pipeline.
33
"""
44

5-
import numpy as np
65

76
from keras.models import Sequential
87
from keras.layers import Dense, Dropout, Flatten
98
from keras.layers import Conv2D, Conv1D, GlobalAveragePooling2D
109
from datagenerator import DataGenerator
1110
from sklearn.model_selection import train_test_split
1211
from sklearn.preprocessing import LabelEncoder
12+
import numpy as np
1313
import itertools
1414
import os
1515

@@ -44,19 +44,12 @@
4444
# Design model
4545
model = Sequential()
4646
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(None, None, 1)))
47-
#model.add(Conv1D(256, kernel_size=(3), activation='relu', input_shape=(None, 1)))
4847
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu'))
4948
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu'))
5049
model.add(Conv2D(32, kernel_size=(3, 3), activation='relu'))
51-
#model.add(Conv2D(32, kernel_size=(3, 3), activation='relu'))
52-
#model.add(Conv2D(32, kernel_size=(3, 3), activation='relu'))
53-
#model.add(Conv2D(32, kernel_size=(3, 3), activation='relu'))
5450
model.add(GlobalAveragePooling2D(data_format='channels_last'))
55-
#model.add(Dropout(0.25))
5651

57-
#model.add(Flatten())
5852
model.add(Dense(168, activation='relu'))
59-
#model.add(Dropout(0.25))
6053
model.add(Dense(168, activation='softmax'))
6154

6255
model.compile(loss='categorical_crossentropy',
@@ -74,7 +67,3 @@
7467

7568
#model.save_weights("/Users/ghunk/Desktop/GRADUATE/CSC_464/Final_Project/weights.h5py")
7669
model.save_weights("/home/ghunkins/weights.h5py")
77-
78-
79-
#steps_per_epoch = len(Train_IDs)//params['batch_size'],
80-
#validation_steps = len(Test_IDs)//params['batch_size'],

README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
# Binaural-Source-Localization-CNN
1+
# Binaural-Source-Localization-CNN
2+
3+
### Basic Information
4+
---
5+
**Author:** Gregory Hunkins
6+
7+
**Organization:** University of Rochester
8+
9+
**License:** MIT
10+
11+
**Abstract:** A Convolutional Neural Network (CNN) classification system was designed for the task of source localization of human voices in 3-D space. A new dataset, VoiceBin100K, is introduced to accomplish this task and for future work in the field. The CNN inputs variable-length binaurual short- time Fourier Transform (STFT) magnitude and phase features and predicts location of the speaker’s voice according to 168 location classes.
12+
13+
14+
### Running The Code
15+
---
16+
17+
Reference: https://cs.rochester.edu/~cxu22/t/577F17/bluehive_tutorial.html
18+
19+
### Data
20+
---
21+
Please contact [email protected] for access to the data. A public link will available shortly.

0 commit comments

Comments
 (0)