def transcribe_file(model_file, flac_paths, save_path, sequence_length, onset_threshold, frame_threshold, device):
    model = torch.load(model_file, map_location=device).eval()
    summary(model)
    for flac_path in flac_paths:
        print(f'Processing {flac_path}...', file=sys.stderr)
        audio = load_and_process_audio(flac_path, sequence_length, device)
        predictions = transcribe(model, audio)
        (p_est, i_est, v_est) = extract_notes(predictions['onset'], predictions['frame'], predictions['velocity'], onset_threshold, frame_threshold)
        scaling = (HOP_LENGTH / SAMPLE_RATE)
        i_est = (i_est * scaling).reshape((- 1), 2)
        p_est = np.array([midi_to_hz((MIN_MIDI + midi)) for midi in p_est])
        os.makedirs(save_path, exist_ok=True)
        pred_path = os.path.join(save_path, (os.path.basename(flac_path) + '.pred.png'))
        save_pianoroll(pred_path, predictions['onset'], predictions['frame'])
        midi_path = os.path.join(save_path, (os.path.basename(flac_path) + '.pred.mid'))
        save_midi(midi_path, p_est, i_est, v_est)
def transcribe_file(model_file, flac_paths, save_path, sequence_length, onset_threshold, frame_threshold, device):
    model = torch.load(model_file, map_location=device).eval()
    summary(model)
    for flac_path in flac_paths:
        print(f'Processing {flac_path}...', file=sys.stderr)
        audio = load_and_process_audio(flac_path, sequence_length, device)
        predictions = transcribe(model, audio)
        (p_est, i_est, v_est) = extract_notes(predictions['onset'], predictions['frame'], predictions['velocity'], onset_threshold, frame_threshold)
        scaling = (HOP_LENGTH / SAMPLE_RATE)
        i_est = (i_est * scaling).reshape((- 1), 2)
        p_est = np.array([midi_to_hz((MIN_MIDI + midi)) for midi in p_est])
        os.makedirs(save_path, exist_ok=True)
        pred_path = os.path.join(save_path, (os.path.basename(flac_path) + '.pred.png'))
        save_pianoroll(pred_path, predictions['onset'], predictions['frame'])
        midi_path = os.path.join(save_path, (os.path.basename(flac_path) + '.pred.mid'))
        save_midi(midi_path, p_est, i_est, v_est)