Reputation: 155
I found some example code for getting pitch using aubio, but I'm not sure what to change to get it to display the pitch in second increments:
import sys
from aubio import source, pitch, freqtomidi
if len(sys.argv) < 2:
print "Usage: %s <filename> [samplerate]" % sys.argv[0]
sys.exit(1)
filename = sys.argv[1]
downsample = 1
samplerate = 44100 / downsample
if len( sys.argv ) > 2: samplerate = int(sys.argv[2])
win_s = 4096 / downsample # fft size
hop_s = 512 / downsample # hop size
s = source(filename, samplerate, hop_s)
samplerate = s.samplerate
tolerance = 0.8
pitch_o = pitch("yin", win_s, hop_s, samplerate)
pitch_o.set_tolerance(tolerance)
pitches = []
confidences = []
total_frames = 0
while True:
samples, read = s()
pitch = pitch_o(samples)[0]
pitch = int(round(pitch))
confidence = pitch_o.get_confidence()
#if confidence < 0.8: pitch = 0.
print "%f %f %f" % (total_frames / float(samplerate), pitch, confidence)
pitches += [pitch]
confidences += [confidence]
total_frames += read
if read < hop_s: break
Also, is it possible for me to do this directly from output instead of a wav file?
Upvotes: 1
Views: 2751
Reputation: 390
This script (also at aubio/python/demos/demo_pitch.py
) extracts pitch candidate for every audio frame (here 512./44100 * 1000 = 11.6ms).
display the pitch in second increments
What do you mean by "in second increments"? The 'overall' pitch for each consecutive 1-second long segments? You could take np.median(pitches)
.
The new pitch after each note change? You could process the output and group similar pitch candidates into notes.
Or just use aubionotes
directly.
do this directly from output
From which "output" do you mean?
See also run aubiopitch continuously on a file descriptor.
Please ask your aubio questions @ https://github.com/aubio/aubio.
Upvotes: 1