import abjad as abj from IPython.display import Audio from subprocess import call from audioread import audio_open import scipy import numpy as np %load_ext abjad.ext.ipython %matplotlib inline %pylab inline rc('font',**{'family':'sans-serif','sans-serif':['Helvetica'], 'size': 22}) rc('text', usetex=True) # Bach in G Major bach_treble = abj.Staff("d''g'8a'b'c''d''4 g'-.g'-. e''c''8d''e''fs''g''4 g'-.g'-. \\\\ c''d''8c''b'a'b'4 c''8b'a'g'fs'4 g'8a'b'g'a'2.") abj.attach(abj.KeySignature('g'), bach_treble) abj.attach(abj.TimeSignature((3,4)), bach_treble) abj.attach(abj.spannertools.PhrasingSlur(), bach_treble[0:6]) abj.attach(abj.spannertools.PhrasingSlur(), bach_treble[8:14]) abj.attach(abj.spannertools.PhrasingSlur(), bach_treble[16:22]) abj.attach(abj.spannertools.PhrasingSlur(), bach_treble[22:27]) abj.attach(abj.spannertools.PhrasingSlur(), bach_treble[27:32]) bach_bass = abj.Staff("2 a4 b2. c' b a2 fs4 g2 c'4 d' b g d' d8 (c' b a)") abj.attach(abj.KeySignature('g'), bach_bass) abj.attach(abj.Clef('bass'), bach_bass) # we're only going to play with the treble score, # change to the commented line to also get the bass score #bach = abj.scoretools.Score([bach_treble, bach_bass]) bach = abj.scoretools.Score([bach_treble]) abj.show(bach) sffile = {'sine':'Sine Wave.sf2', 'piano':'JV1080_Nice_Piano_m.sf2'} signal = {} sr = 0 def load_audio_from_file(filename): # load the audio data from the file temp = bytearray() sr = 0 with audio_open(filename) as audio: sr = audio.samplerate nchannels = audio.channels # chunk size can be specified with 'block_samples' (default 1024): for chunk in audio.read_data(): temp.extend(chunk) data = frombuffer(temp, dtype='