def main(): djv = Dejavu(config) if request.method == 'GET': file_log = open("hashes_samples.log", "r") array_hashes = file_log.readlines() elif request.method == 'POST': json_local = request.get_json() if len(json_local['hashes']) == 0: return jsonify({'error': 'invalid input'}) string_hashes = json_local['hashes'] string_hashes = string_hashes.replace("[", "") string_hashes = string_hashes.replace("]", "") array_hashes = string_hashes.rstrip().split(', ') hashes = dict() samples_indexes = [] for string_hash in array_hashes: sample_index, hash_local, offset = string_hash.rstrip().split('|') if sample_index in hashes: hashes[sample_index].append((hash_local, int(offset))) else: hashes[sample_index] = [] if sample_index not in samples_indexes: samples_indexes.append(sample_index) matches = [] for sample_index in samples_indexes: matches.extend(djv.rest_find_matches(hashes[sample_index])) return jsonify(djv.align_matches(matches))
djv = Dejavu(config) with open('./input.txt', 'r') as content_file: inHex = content_file.read().strip().decode('string-escape') # print len(inHex) data = np.fromstring(inHex, np.int16) # print len(data) # print data[:128] matches = [] matches.extend(djv.find_matches(data)) # print matches song = djv.align_matches(matches) result = None if song is not None: result = dict() result["song_name"] = song["song_name"] result["offset"] = str(song["offset"]) offset = song["offset"] result["seconds"] = (offset * (DEFAULT_WINDOW_SIZE - DEFAULT_WINDOW_SIZE*DEFAULT_OVERLAP_RATIO) + DEFAULT_WINDOW_SIZE*DEFAULT_OVERLAP_RATIO) / DEFAULT_FS print json.dumps(result)