def do_recording(self, start_time): """4. Alice requests recording (4 and 5 are called synchronous at ``start_time``) Function waits until ``start_time`` and then starts recording :param start_time: Absolute time when recording should start :type start_time: int """ log.info('4. Alice requests recording') if self.recording_use_file: # load recording from file #left_channel, right_channel, self.recording_samplerate = load_stereo(self.recording_file) #self.recording_data = left_channel self.recording_data, self.recording_samplerate = load_mono(self.recording_file) else: # start recording at start_time self.recording_data, self.recording_samplerate = record_at_time("client.wav", 7, start_time)
def record_at_time(filename, duration, start_time): # init recorder recording = AudioRecording(filename, duration) end_time = start_time+duration log.debug("Recording Start time: "+str(start_time)) log.debug("Recording End time: "+str(end_time)) # starting at start_time while True: if (time.time() >= start_time): # now go on! break log.info('Recording thread started at '+str(time.time())) # record in thread thread.start_new_thread(recording.record_start, (end_time,)) # init and start gobject c threads loop = gobject.MainLoop() gobject.threads_init() context = loop.get_context() # record and do thread loop until end_time while True: # do gobject iteration context.iteration(True) if (time.time() >= end_time): # terminate gobject thread loop.quit() break # load recorded file recording_data, recording_samplerate = load_mono(filename) return recording_data, recording_samplerate
def remote_recording(self, start_time): """5. remote recording (4 and 5 are called synchron at ``start_time``) Function waits until ``start_time`` and then starts recording :param start_time: Absolute time when recording should start :type start_time: int """ log.info('5. remote recording') if self.recording_use_file: # load recording from file self.recording_data, self.recording_samplerate = load_mono(self.recording_file) return True else: # start recording at start_time self.recording_data, self.recording_samplerate = record_at_time("server.wav", 7, start_time) return True
base = "/home/ds1/Projekte/Bachelorarbeit/Program/recordings/" # fingerprinting based on energy difference import fingerprint_energy_diff import logging # Logging all above INFO level, output to stderr logging.basicConfig(#format='%(asctime)s %(levelname)-8s %(message)s') format='%(levelname)-8s %(message)s') log = logging.getLogger("fuzzy_pairing") log.setLevel(logging.DEBUG) # load channels: left_channel, samplerate = load_mono(base+'1.5_3/high/music5.wav') right_channel, samplerate = load_mono(base+'1.5_3/high/music1.wav') # fingerprint energy diff fingerprint_left = fingerprint_energy_diff.get_fingerprint(left_channel, samplerate) fingerprint_right = fingerprint_energy_diff.get_fingerprint(right_channel, samplerate) print repr(fingerprint_left) print repr(fingerprint_right) # calculate hamming distance between fingerprints distance = hamming_distance(fingerprint_left, fingerprint_right) length = len(fingerprint_left) print length, distance print('Correlation %: '+str(1-float(distance)/float(length)))
log.setLevel(logging.DEBUG) path = "/home/ds1/Projekte/Fuzzy Pairing Paper/Versuche Audiodateien/" matrix = list() # get all files in all subdirectories etc. for root, dirs, files in os.walk(path): for name in files: filename = os.path.join(root, name) print filename print "current file is: " + name mono_channel, samplerate = load_mono(filename) # fingerprint energy diff fingerprint = fingerprint_energy_diff.get_fingerprint(mono_channel, samplerate) # you can add more analysis using helper_analysis here # and write the results in the matrix for further analyzing matrix.append([filename,fingerprint]) print matrix # save it with pickle, can later be analyzed with file('analysis_matrix.txt', 'wr') as f: pickle.dump(matrix, f)