Mercurial > hg > chime-home-dataset-annotation-and-baseline-evaluation-code
annotate gmm_baseline_experiments/external_libs/librosa/librosa-0.3.1/examples/estimate_tuning.py @ 5:b523456082ca tip
Update path to dataset and reflect modified chunk naming convention.
author | peterf |
---|---|
date | Mon, 01 Feb 2016 21:35:27 +0000 |
parents | cb535b80218a |
children |
rev | line source |
---|---|
peterf@2 | 1 #!/usr/bin/env python |
peterf@2 | 2 '''CREATED:2013-12-09 00:02:54 by Brian McFee <brm2132@columbia.edu> |
peterf@2 | 3 |
peterf@2 | 4 Estimate the tuning (deviation from A440) of a recording. |
peterf@2 | 5 |
peterf@2 | 6 Usage: ./tuning.py [-h] input_file |
peterf@2 | 7 ''' |
peterf@2 | 8 from __future__ import print_function |
peterf@2 | 9 |
peterf@2 | 10 import argparse |
peterf@2 | 11 import sys |
peterf@2 | 12 import librosa |
peterf@2 | 13 |
peterf@2 | 14 |
peterf@2 | 15 def estimate_tuning(input_file): |
peterf@2 | 16 '''Load an audio file and estimate tuning (in cents)''' |
peterf@2 | 17 |
peterf@2 | 18 print('Loading ', input_file) |
peterf@2 | 19 y, sr = librosa.load(input_file) |
peterf@2 | 20 |
peterf@2 | 21 print('Separating harmonic component ... ') |
peterf@2 | 22 y_harm = librosa.effects.harmonic(y) |
peterf@2 | 23 |
peterf@2 | 24 print('Estimating tuning ... ') |
peterf@2 | 25 # Just track the pitches associated with high magnitude |
peterf@2 | 26 tuning = librosa.feature.estimate_tuning(y=y_harm, sr=sr) |
peterf@2 | 27 |
peterf@2 | 28 print('{:+0.2f} cents'.format(100 * tuning)) |
peterf@2 | 29 |
peterf@2 | 30 |
peterf@2 | 31 def process_arguments(args): |
peterf@2 | 32 '''Argparse function to get the program parameters''' |
peterf@2 | 33 |
peterf@2 | 34 parser = argparse.ArgumentParser(description='Tuning estimation example') |
peterf@2 | 35 |
peterf@2 | 36 parser.add_argument('input_file', |
peterf@2 | 37 action='store', |
peterf@2 | 38 help='path to the input file (wav, mp3, etc)') |
peterf@2 | 39 |
peterf@2 | 40 return vars(parser.parse_args(args)) |
peterf@2 | 41 |
peterf@2 | 42 |
peterf@2 | 43 if __name__ == '__main__': |
peterf@2 | 44 # Get the parameters |
peterf@2 | 45 parameters = process_arguments(sys.argv[1:]) |
peterf@2 | 46 |
peterf@2 | 47 # Run the beat tracker |
peterf@2 | 48 estimate_tuning(parameters['input_file']) |