I'm using in Python a VAMP plugin:
import vamp
import librosa
data, rate = librosa.load("example.mp3")
chroma = vamp.collect(data, rate, "nnls-chroma:nnls-chroma")
I have to decode results in a json object. Since the Vamp plugin uses a specific object vampy.RealTime
object to wrap numbers I wrote an Encoder
for that, otherwise you will get a TypeError: (integer) is not JSON serializing
- see here for this specific error: "TypeError: (Integer) is not JSON serializable" when serializing JSON in Python?
For this reason I wrote a custom JSON Encoder that uses the conversion to number from the vampy.RealTime
object, taken from here
import json
class VampJSONEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, vamp.vampyhost.RealTime):
r = vamp.vampyhost.RealTime('seconds', obj)
return r
return super(VampJSONEncoder, self).default(obj)
but when I run it like
json.dumps(chroma, sort_keys=True, indent=4, cls=VampJSONEncoder)
I get a
RuntimeError: maximum recursion depth exceeded while calling a Python object