예제 #1
0
def _main(wav_file, input_json, output_json):
    '''
		first detect pitches 
	'''
    mfshs = MFSHS(wav_file)
    mfshs.pitch_detector()
    pitches = mfshs.pitches
    zero_amp_frame = mfshs.zeroAmploc

    score_note, pauseLoc = parse_musescore(input_json)
    '''
		second detect onset 
	'''
    onset_frame = detector_onset(wav_file, pitches, score_note)
    '''
		sw alignment
	'''
    match_loc_info = sw_alignment(pitches, onset_frame, score_note)
    '''
		post process and save result
	'''
    onset_offset_pitches = trans_onset_and_offset(match_loc_info, onset_frame,
                                                  pitches)
    evaluator = Evaluator(output_json, onset_offset_pitches, zero_amp_frame,
                          score_note, pauseLoc)
예제 #2
0
def main(wav_file, score_file):
    '''
		first detect pitches 
	'''
    mfshs = MFSHS(wav_file)
    mfshs.pitch_detector()
    pitches = mfshs.pitches
    zero_amp_frame = mfshs.zeroAmploc
    energes = mfshs.energes

    score_note, note_type, pauseLoc = parse_musescore(
        score_file)  ## parse musescore
    '''
		second detect onset 
	'''
    onset_frame = detector_onset(wav_file, pitches, score_note)
    '''
		sw alignment
	'''
    match_loc_info = sw_alignment(pitches, onset_frame, score_note)
    '''
		post process and save result
	'''
    onset_offset_pitches = trans_onset_and_offset(match_loc_info, onset_frame,
                                                  pitches)
    filename_json = os.path.splitext(wav_file)[0] + ".json"
    evaluator = Evaluator(filename_json, onset_offset_pitches, zero_amp_frame,
                          score_note, pauseLoc, note_type)
    save_files(wav_file, onset_frame, pitches, evaluator.det_note, score_note)
    '''
예제 #3
0
def cal_system_acc(wav_files):
    def cal_acc(det_note, score_note):
        det_note = np.array(det_note)
        score_note = np.array(score_note)
        det_note = is_octive(det_note, score_note)
        diff_note = abs(det_note - score_note)
        acc_index = np.where(diff_note <= 0.8)[0]
        accuracy = len(acc_index) / len(diff_note)
        return accuracy, diff_note

    sys_acc_res = dict()
    for index in range(len(wav_files)):
        json_path = '/home/data/lj/onset_detect/MUS/evaluate/'
        wav_file = wav_files[index]
        fid = os.path.basename(wav_file)[0:-4]
        #score_note = np.array(score_notes[fid]).astype(int)
        json_path = os.path.join(json_path, fid)
        score_file = [
            os.path.join(json_path, x) for x in os.listdir(json_path)
            if x.endswith('json')
        ][0]

        mfshs = MFSHS(wav_file)
        mfshs.pitch_detector()
        pitches = mfshs.pitches
        zero_amp_frame = mfshs.zeroAmploc

        score_note, note_types, pauseLoc = parse_musescore(
            score_file)  # parse musescore

        predictor = predictor_onset()
        onset_time = predictor.predict(wav_file)

        onset_frame = predictor.onset_frame

        onset_frame = post_cnn_onset(pitches, onset_frame)

        match_loc_info = sw_alignment(pitches, onset_frame, score_note)

        onset_offset_pitches = trans_onset_and_offset(match_loc_info,
                                                      onset_frame, pitches)
        filename_json = os.path.splitext(wav_file)[0] + ".json"
        evaluator = Evaluator(filename_json, onset_offset_pitches,
                              zero_amp_frame, score_note, pauseLoc, note_types)

        accuracy, diff_note = cal_acc(evaluator.det_note, score_note)
        temp = dict()
        temp['acc'] = accuracy
        temp['dnote'] = evaluator.det_note
        temp['snote'] = score_note
        temp['diff_note'] = diff_note

        sys_acc_res[fid] = temp

    return sys_acc_res
예제 #4
0
def main(wav_file, score_file):
    # mfshs = MFSHS(wav_file)
    # mfshs.pitch_detector()
    # pitches = mfshs.pitches #返回音é«Ë?
    # print(type(pitches),pitches)
    # zero_amp_frame = mfshs.zeroAmploc   #音高�索�
    # print(type(zero_amp_frame),zero_amp_frame)

    # pitches_filepath = "/home/ywm/MUSIC/new_solfege_pYIN/data/1011_pitch.txt"
    # pitches = []
    # with open(pitches_filepath,'r') as f:
    #   a = f.readlines()
    #   for i in a:
    #     pitches.append(float(i.split()[0]))
    # pitches = np.array(pitches)

    pitches = demo.pYIN(wav_file)
    pitches = np.array(pitches) - 20
    pitches = np.where((pitches < 0.0), 0, pitches)

    #print(type(pitches),pitches)
    zero_amp_frame = np.where(pitches == 0)[0]
    score_note, note_types, pauseLoc = parse_musescore(  #解析json乐谱,返回乐谱中的note值和休止符位ç�
        score_file)  # parse musescore

    predictor = predictor_onset()
    onset_time = predictor.predict(wav_file)

    #draw_array(predictor.onset_pred)
    onset_frame = predictor.onset_frame

    onset_frame = post_cnn_onset(pitches, onset_frame)
    #print("onset_frame:",onset_frame)
    match_loc_info = sw_alignment(pitches, onset_frame, score_note)
    #print(2)
    onset_offset_pitches = trans_onset_and_offset(match_loc_info, onset_frame,
                                                  pitches)
    #print("onset_offset_pitches:",onset_offset_pitches)
    filename_json = os.path.splitext(wav_file)[0] + ".json"
    evaluator = Evaluator(filename_json, onset_offset_pitches, zero_amp_frame,
                          score_note, pauseLoc, note_types)
    #print(4)
    save_files(wav_file, onset_frame, pitches, evaluator.det_note, score_note,
               onset_offset_pitches['onset_frame'])

    #print(5)
    return evaluator.score
예제 #5
0
def print_save_acc(wav_files, ground_notes, score_notes):
    fwt = open('log/acc.txt', 'w')
    for index in range(len(wav_files)):
        json_path = '/home/data/lj/onset_detect/MUS/evaluate/'
        wav_file = wav_files[index]
        fid = os.path.basename(wav_file)[0:-4]
        # score_note = np.array(score_notes[fid]).astype(int)
        json_path = os.path.join(json_path, fid)
        score_file = [
            os.path.join(json_path, x) for x in os.listdir(json_path)
            if x.endswith('json')
        ][0]

        mfshs = MFSHS(wav_file)
        mfshs.pitch_detector()
        pitches = mfshs.pitches
        zero_amp_frame = mfshs.zeroAmploc

        score_note, note_types, pauseLoc = parse_musescore(
            score_file)  # parse musescore
        predictor = predictor_onset()
        onset_time = predictor.predict(wav_file)

        onset_frame = predictor.onset_frame

        onset_frame = post_cnn_onset(pitches, onset_frame)

        match_loc_info = sw_alignment(pitches, onset_frame, score_note)

        onset_offset_pitches = trans_onset_and_offset(match_loc_info,
                                                      onset_frame, pitches)
        filename_json = os.path.splitext(wav_file)[0] + ".json"
        evaluator = Evaluator(filename_json, onset_offset_pitches,
                              zero_amp_frame, score_note, pauseLoc, note_types)

        print(wav_file)
        sys_acc, sys_diff_note = cal_acc(evaluator.det_note, score_note)

        gnote = ground_notes[fid]
        snote = score_note
        ground_acc, ground_diff_note = cal_acc(gnote, snote)

        ground_sys_acc, ground_sys_diff_note = cal_acc(evaluator.det_note,
                                                       gnote)

        strs = '{}\t{}\t{}'.format('ground', 'sys', 'ground_sys')
        print(strs)
        strs = '{:.3f}\t{:.3f}\t{:.3f}\n'.format(ground_acc, sys_acc,
                                                 ground_sys_acc)
        print(strs)

        file_name = os.path.join('log', fid + '.txt')
        with open(file_name, 'w') as fw:
            fw.write('gnote\t\tsnote\t\tdnote\n')
            for index in xrange(len(gnote)):
                fw.write('{:.3f}\t\t{:.3f}\t\t{:.3f}\t\t'.format(
                    gnote[index], snote[index], evaluator.det_note[index]))

                fw.write('{:.3f}\t\t{:.3f}\t\t{:.3f}\n'.format(
                    ground_diff_note[index], sys_diff_note[index],
                    ground_sys_diff_note[index]))

            fw.write('{:.3f}\t\t{:.3f}\t\t{:.3f}\n'.format(
                ground_acc, sys_acc, ground_sys_acc))

        fwt.write(wav_file + '\n')
        fwt.write(strs)
        fwt.write('\n')
        fwt.flush()
    fwt.close()