.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_examples/ex2_compute_features.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr__examples_ex2_compute_features.py: Compute features ================ .. GENERATED FROM PYTHON SOURCE LINES 5-17 .. code-block:: Python import os import librosa import librosa.display import matplotlib.pyplot as plt import numpy as np import rtvamp # set VAMP_PATH to rtvamp package dir to find example plugins os.environ["VAMP_PATH"] = os.path.dirname(rtvamp.__file__) .. GENERATED FROM PYTHON SOURCE LINES 18-20 Load sample audio data ---------------------- .. GENERATED FROM PYTHON SOURCE LINES 20-22 .. code-block:: Python y, sr = librosa.load(librosa.ex("trumpet")) .. rst-class:: sphx-glr-script-out .. code-block:: none Downloading file 'sorohanro_-_solo-trumpet-06.ogg' from 'https://librosa.org/data/audio/sorohanro_-_solo-trumpet-06.ogg' to '/home/runner/.cache/librosa'. .. GENERATED FROM PYTHON SOURCE LINES 23-25 Compute features with rtvamp ---------------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-39 .. code-block:: Python t_rms, y_rms = rtvamp.compute_features( y, sr, plugin="example-plugin:rms", blocksize=256, ) t_sro, y_sro = rtvamp.compute_features( y, sr, plugin="example-plugin:spectralrolloff", blocksize=256, parameter={"rolloff": 0.5}, ) .. GENERATED FROM PYTHON SOURCE LINES 40-42 Plot features with spectrogram ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 42-54 .. code-block:: Python fig, ax = plt.subplots(nrows=3, ncols=1, sharex=True, tight_layout=True) D = librosa.amplitude_to_db(np.abs(librosa.stft(y)), ref=np.max) librosa.display.specshow(D, x_axis="time", y_axis="linear", sr=sr, ax=ax[0]) ax[0].set(title="STFT") ax[1].plot(t_rms, y_rms[0]) ax[1].set(title="RMS") ax[2].plot(t_sro, y_sro[0]) ax[2].set(title="Spectral Rolloff") plt.show() .. image-sg:: /_examples/images/sphx_glr_ex2_compute_features_001.png :alt: STFT, RMS, Spectral Rolloff :srcset: /_examples/images/sphx_glr_ex2_compute_features_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 16.456 seconds) .. _sphx_glr_download__examples_ex2_compute_features.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ex2_compute_features.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ex2_compute_features.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ex2_compute_features.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_