class RV(RecycleView):
    # Initials
    path = os.getcwd() + "/"
    song = os.getcwd() + "/bird-sounds/"
    bird_path = path + "bird-dir/bird-types.txt"
    bird_names = open(bird_path, "r")

    # Birds List
    birds = initiate_birds()

    # Birds and their songs Dictionary
    libr = initiate_libr(birds)

    def __init__(self, **kwargs):
        super(RV, self).__init__(**kwargs)
        tmp = list()
        for x in self.libr.keys():
            tmp.append(str(f'--{x}--'))
            for y in self.libr.get(x):
                tmp.append(y)
        self.data = [{'text': str(x)} for x in tmp]
Example #2
0
# ignore all future warnings
simplefilter(action='ignore', category=FutureWarning)

SAMPLE_RATE = 44100

#Initials
path = os.getcwd() + "/"
bird_path = path + "bird-dir/bird-types.txt"
bird_names = open(bird_path, "r")
pth = os.getcwd() + "/"

#Birds List
birds = initiate_birds()

#Birds and their songs Dictionary
libr = initiate_libr(birds)

#Read Dataset
train = pd.read_csv(f'{pth}train.csv')
test = pd.read_csv(f'{pth}test.csv')

train = pd.DataFrame(train)
test = pd.DataFrame(test)


def get_mfcc(name, path):
    b, _ = librosa.core.load(name, sr=SAMPLE_RATE)
    assert _ == SAMPLE_RATE
    gmm = librosa.feature.mfcc(b, sr=SAMPLE_RATE, n_mfcc=20)
    return pd.Series(np.hstack((np.mean(gmm, axis=1), np.std(gmm, axis=1))))
Example #3
0
def Create():
    SAMPLE_RATE = 44100

    #Initials
    path = os.getcwd() + "/"
    song = os.getcwd() + "/bird-sounds/"
    bird_path = path + "bird-dir/bird-types.txt"
    bird_names = open(bird_path, "r")

    #Birds List
    birds = initiate_birds()

    #Birds and their songs Dictionary
    libr = initiate_libr(birds)
    #Define train and test dicts

    ones = open('train.csv', 'w').close()
    zeros = open('test.csv', 'w').close()

    train = dict()
    test = dict()

    for st in libr.keys():
        train.update({st: []})
        test.update({st: []})

    #Init train and test dicts
    for l in libr.keys():
        counter = 0
        for x in libr[l]:
            if counter >= round(len(libr[l]) * 0.9):
                test.update(l=test[l].append(x))
                counter += 1
            else:
                train.update(l=train[l].append(x))
                counter += 1

    train.pop('l')
    test.pop('l')

    #x = open('train.csv', 'w+').close()

    #Create train.csv
    row = ['bird', 'song']
    with open('train.csv', 'w') as csvFile:
        writer = csv.writer(csvFile)
        writer.writerow(row)

    for t in train.keys():
        for val in train[t]:
            file = open('train.csv', 'a', newline='')
            with file:
                imp = t[:] + "~~" + song + t + "/" + val
                writer = csv.writer(file)
                writer.writerow(imp.split("~~"))
    csvFile.close()

    #Create test,csv
    with open('test.csv', 'w') as csvFile:
        writer = csv.writer(csvFile)
        writer.writerow(row)

    for t in test.keys():
        for val in test[t]:
            file = open('test.csv', 'a', newline='')
            with file:
                imp = t[:] + "~~" + song + t + "/" + val
                writer = csv.writer(file)
                writer.writerow(imp.split("~~"))
    csvFile.close()