cat40
cat40

Reputation: 318

Use of aubio.note() in python?

I'm trying to use aubio to find the notes in a recording. Whenever I call aubio.notes with aubio.notes(filename), the python shell crashes (windows dialogue: pythonw.exe has stopped working). The only "documentation" I found are these pages for the command line commands. I figured out the first argument is a string (presumably file name?). Based on the uses of aubio.pitch and aubio.tempo and aubio.source, note is a class, and methods are used on an instance of this class. Does anyone know how to use this?

It does work when called as n = aubio.note(), but I've no clue where to go from there

Upvotes: 0

Views: 728

Answers (1)

Oriol Pique
Oriol Pique

Reputation: 1

aubio.notes doesn't get a filename as parameter, it is a little more complicated:

class aubio.notes(method="default", buf_size=1024, hop_size=512, samplerate=44100)

aubio python documentation

I wrote this example (but I think it's already in the example linked above):

import aubio 
import time 
hop_s=256 
win_s=1024
samplerate=44100 
filename=?Audio file to process
def ReadInput(src:aubio.source):
    return src() 
s = aubio.source(filename, samplerate,  hop_s) 
samplerate = s.samplerate
notes_o = aubio.notes("default",win_s, hop_s, samplerate)
while(True):
    samples,read=ReadInput(s)
    #print("ReadInput:",read," samples",samplerate," samplerate") 
    if(read<hop_s):
        exit(0) 
    new_note = notes_o(samples,hop_s=hop_s,win_s=win_s,samplerate=samplerate) 
    if(new_note[0]!=0):
        print("noteon:",new_note,"note name:",aubio.midi2note(int(new_note[0])),"velocity:",new_note[1])
    if(new_note[2]!=0):
        print("noteoff",new_note,"note name:",aubio.midi2note(int(new_note[0])),"velocity:",new_note[1])

    sleepsecs=float(float(read)/float(samplerate))
    #print("sleepsecs:",sleepsecs) 
    time.sleep(sleepsecs)

Upvotes: 0

Related Questions