Skip to content

Instantly share code, notes, and snippets.

View bmcfee's full-sized avatar

Brian McFee bmcfee

View GitHub Profile
@bmcfee
bmcfee / ks_key.py
Created September 7, 2017 19:02
Krumhansl-Schmuckler key estimation
import numpy as np
import scipy.linalg
import scipy.stats
def ks_key(X):
'''Estimate the key from a pitch class distribution
Parameters
----------
X : np.ndarray, shape=(12,)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env python
'''Compute VGGish features for a batch of files'''
import argparse
import os
import sys
import librosa
import pandas as pd
@bmcfee
bmcfee / load_audio.py
Created August 5, 2017 19:32
audio preprocessing for soundnet
import numpy as np
import librosa
def load_audio(filename, **kwargs):
y, sr = librosa.load(filename, sr=22050, mono=True, **kwargs)
y = librosa.util.normalize(y) * 256
return y[np.newaxis, :, np.newaxis]
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bmcfee
bmcfee / numpy json
Created July 5, 2017 20:29
serializing numpy values for jolly good times!
In [1]: import numpy as np
In [2]: import json
In [3]: json.dumps(np.float64(2.0))
Out[3]: '2.0'
In [4]: json.dumps(np.float32(2.0))
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.