def costalignment(a): plt.clf() #plt.figure(figsize=(8,6)) plt.gray() fixcosts(a) states = np.arange(0, a.state_count() + 1) times = np.arange(0, a.frame_count()) / audio.sample_rate * audio.nsamples #plt.axes([0,0,np.max(times),np.max(states)]) x, y = np.meshgrid(times, states) plt.pcolormesh(x, y, a.costs.transpose()) test_plot, = plt.plot(times, [s + 1 for s in a.path]) wav = data.get_audio(a.name) score = data.get_score(a.name, wav.total_length) truth = data.get_truth(a.name, score, wav) if truth: t = truth_path = truth.get_path() truth_plot, = plt.plot(times, [s + 1 for s in truth_path]) bx = plt.legend([test_plot, truth_plot], ("Automatic alignment", "Ground truth"),\ numpoints=1, handletextpad=0.5, loc="upper left") bx.draw_frame(False) plt.ylabel('State number in score sequence') plt.xlabel('Time in audio recording (s)') processplt(a, plt, "costmap")
def costalignment(a): plt.clf() # plt.figure(figsize=(8,6)) plt.gray() fixcosts(a) states = np.arange(0, a.state_count() + 1) times = np.arange(0, a.frame_count()) / audio.sample_rate * audio.nsamples # plt.axes([0,0,np.max(times),np.max(states)]) x, y = np.meshgrid(times, states) plt.pcolormesh(x, y, a.costs.transpose()) test_plot, = plt.plot(times, [s + 1 for s in a.path]) wav = data.get_audio(a.name) score = data.get_score(a.name, wav.total_length) truth = data.get_truth(a.name, score, wav) if truth: t = truth_path = truth.get_path() truth_plot, = plt.plot(times, [s + 1 for s in truth_path]) bx = plt.legend( [test_plot, truth_plot], ("Automatic alignment", "Ground truth"), numpoints=1, handletextpad=0.5, loc="upper left", ) bx.draw_frame(False) plt.ylabel("State number in score sequence") plt.xlabel("Time in audio recording (s)") processplt(a, plt, "costmap")
def align(name, lik_method, path_method, const_width=None, rel_width=None): a = data.get_alignment(name, lik_method, path_method) if a == None: audio = data.get_audio(name) score = data.get_score(name) proc = AlignmentProcessor(lik_method, path_method) a = proc.align(audio, score, const_width, rel_width) truth = data.get_truth(name, score, audio) if truth: a.truth_path = truth.get_path() a.set_name(name) data.save_alignment(a) return a
def truth(request, seconds, name): truth = data.get_truth(name, seconds)
#!/usr/bin/env python import data score = data.get_score("mozart") audio = data.get_audio("mozart") truth = data.get_truth("mozart", score, audio) print truth.get_path()