def populate(self, directory): ''' Analyzes all audio files in a directory and add their fingerprint to the database. Writes result to disk when done. Args: directory: directory containing audio files. ''' audio_files = sorted(soundfiles.find_files(directory + '/*')) c.notice("Reading {} files...".format(len(audio_files))) i = 0 for filename in audio_files: i += 1 c.write('\r\t-file ' + str(i) + ' of ' + str(len(audio_files))) signal = soundfiles.load_signal(filename) self.add(fingerprint.get_tokens(signal)) c.write("\n") c.notice("Writing database to disk...") self.save() c.succes("Database written")
This program generates random testcases from the pokemon sounds. ''' import soundfiles import random import matplotlib.pyplot as plt import wave import numpy as np import os if not os.path.exists("audio/pokemon"): os.makedirs("audio/pokemon") directory = "training/pokemon/*.wav" files = soundfiles.find_files(directory) for f in files: signal = soundfiles.load_signal(f) ''' initialize the suffix of the new file and the new samples ''' suffix = "" new_samples = signal.samples if random.random() < 0.5: ''' add noise ''' new_samples += 0.05 - 0.1 * np.random.rand(len(new_samples))
This program generates random testcases from the pokemon sounds. ''' import soundfiles import random import matplotlib.pyplot as plt import wave import numpy as np import os if not os.path.exists("audio/pokemon"): os.makedirs("audio/pokemon") directory = "training/pokemon/*.wav" files = soundfiles.find_files(directory) for f in files: signal = soundfiles.load_signal(f) ''' initialize the suffix of the new file and the new samples ''' suffix = "" new_samples = signal.samples if random.random() < 0.5: ''' add noise ''' new_samples += 0.05 - 0.1 * np.random.rand(len(new_samples)) suffix += "-noise"
''' This file tests the classifier. It uses the generates testcases from generate_samples.py. ''' from database import Database from soundfiles import load_signal, find_files from fingerprint import get_tokens import matplotlib.pyplot as plt from random import shuffle from sys import exit database = Database("pokemon", replace=False) classifier = database.as_classifier() filenames = find_files("audio/pokemon/*.wav") if not filenames: print "No files found" exit() print "Start testing classifier with {} files\n".format(len(filenames)) shuffle(filenames) correct_match = 0 wrong_match = 0 no_match = 0 wrong_matches = "" correct_matches = ""