Skip to content

Instantly share code, notes, and snippets.

@xavriley
Created December 1, 2023 13:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xavriley/b72645b2ccb9398308c7dc713a78d4fb to your computer and use it in GitHub Desktop.
Save xavriley/b72645b2ccb9398308c7dc713a78d4fb to your computer and use it in GitHub Desktop.
How to run chordino on a batch of audio files

How to run chordino on a batch of audio files

Method 1 - sonic annotator

I'm working on a mac here so I'm assuming you have bash/terminal available. If you're on Windows you could try setting up Windows Subsytem for Linux maybe? (WSL)

  • Open a terminal, get the version of sonic-annotator for your OS from here: https://code.soundsoftware.ac.uk/projects/sonic-annotator/files
  • Move the downloaded file to your preferred location and extract it (tar -xvf sonic-annotator-1.6-macos.tar.gz was the command I used)
  • Open a terminal, then cd to the sonic-annotator-1.6-macos folder that just got created in the last step
  • find the name of the chordino plugin like so:
$ ./sonic-annotator -l | grep chord
vamp:nnls-chroma:chordino:chordnotes
vamp:nnls-chroma:chordino:harmonicchange
vamp:nnls-chroma:chordino:loglikelihood
vamp:nnls-chroma:chordino:simplechord

These are the available plugin options. I'm using the one ending simplechord for this example but you can use any of these.

  • Generate a "skeleton" config for this plugin by running
./sonic-annotator -s vamp:nnls-chroma:chordino:simplechord > chordino-config.n3

The text in this file should match the options you see in Sonic Visualiser. If you usually change the settings in Sonic Visualiser you need to make those same edits in this .n3 file too.

  • Use this config file to run the plugin on some audio
$ ./sonic-annotator -t chordino-config.n3 /Users/xavriley/Dropbox/Audio/dua-levitating.wav -w csv --csv-stdout
... some output ...
Extracting and writing features... Done
"/Users/xavriley/Dropbox/Audio/dua-levitating.wav",0.000000000,"N"
,2.461315193,"Bm"
,3.947392290,"F#m"
,5.154829932,"Em7"
,6.362267574,"Bm"
,8.637823129,"F#m"
,9.891700680,"G6"
,11.052698413,"Bm7"
,12.910294785,"E"
,13.374693878,"D/F#"
,14.024852608,"C#"
...

Method 2 - Use vamp directly from Python

  • pip install vamp or add it to your requirements.txt
  • Here's an example of me using it in a Python session
$ python
Python 3.9.12 (main, Apr  5 2022, 01:53:17)
[Clang 12.0.0 ] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import vamp
>>> import librosa
>>> y, sr = librosa.load("/Users/xavriley/Dropbox/Audio/dua-levitating.wav")
>>> chords = vamp.collect(y, sr, "nnls-chroma:chordino")
>>> chords
{'list': [{'timestamp':  0.371519274, 'label': 'N'}, {'timestamp':  2.507755102, 'label': 'Bm'}, {'timestamp':  3.900952380, 'label': 'F#m'}, ...

You can see the docs for the Python plugin here: https://pypi.org/project/vamp/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment