Convert Figma logo to code with AI

librosa logolibrosa

Python library for audio and music analysis

7,088
960
7,088
55

Top Related Projects

19,130

Magenta: Music and Art Generation with Machine Intelligence

3,291

a library for audio and music analysis

C++ library for audio and music analysis, description and synthesis, including Python bindings

Python Audio Analysis Library: Feature Extraction, Classification, Segmentation and Applications

2,506

Data manipulation and transformation for audio signal processing, powered by PyTorch

Quick Overview

Librosa is a Python library for music and audio analysis. It provides the building blocks necessary to create music information retrieval systems, offering a comprehensive set of functions for feature extraction, signal processing, and music analysis tasks.

Pros

  • Comprehensive set of audio processing and analysis tools
  • Well-documented with extensive examples and tutorials
  • Integrates seamlessly with popular scientific Python libraries (NumPy, SciPy)
  • Active development and community support

Cons

  • Can be computationally intensive for large audio files
  • Steep learning curve for beginners in audio processing
  • Limited real-time processing capabilities
  • Some advanced features may require additional dependencies

Code Examples

Loading an audio file and plotting its waveform:

import librosa
import librosa.display
import matplotlib.pyplot as plt

y, sr = librosa.load('path/to/audio/file.mp3')
plt.figure(figsize=(12, 4))
librosa.display.waveshow(y, sr=sr)
plt.title('Audio Waveform')
plt.show()

Extracting mel-frequency cepstral coefficients (MFCCs):

import librosa

y, sr = librosa.load('path/to/audio/file.mp3')
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)
print(f"MFCC shape: {mfccs.shape}")

Performing onset detection:

import librosa

y, sr = librosa.load('path/to/audio/file.mp3')
onset_frames = librosa.onset.onset_detect(y=y, sr=sr)
onset_times = librosa.frames_to_time(onset_frames, sr=sr)
print(f"Detected onsets at: {onset_times}")

Getting Started

To get started with Librosa, follow these steps:

  1. Install Librosa using pip:

    pip install librosa
    
  2. Import the library in your Python script:

    import librosa
    
  3. Load an audio file:

    y, sr = librosa.load('path/to/audio/file.mp3')
    
  4. Start analyzing! For example, to compute the chromagram:

    chroma = librosa.feature.chroma_stft(y=y, sr=sr)
    

For more detailed information and examples, refer to the official Librosa documentation.

Competitor Comparisons

19,130

Magenta: Music and Art Generation with Machine Intelligence

Pros of Magenta

  • Focuses on machine learning for music and art generation
  • Provides high-level tools for creative AI applications
  • Includes pre-trained models for various music generation tasks

Cons of Magenta

  • Steeper learning curve for non-ML experts
  • Larger codebase and more dependencies
  • Less suitable for general audio processing tasks

Code Comparison

Magenta (music generation):

melody = mm.Melody(
    steps_per_quarter=4,
    notes=[60, 62, 64, 65, 67, 69, 71, 72]
)
sequence = melody.to_sequence()

Librosa (audio analysis):

y, sr = librosa.load('audio.wav')
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)
chroma = librosa.feature.chroma_stft(y=y, sr=sr)

Summary

Magenta is better suited for creative AI applications in music and art, offering pre-trained models and high-level tools for generation tasks. Librosa, on the other hand, excels in general audio processing and analysis, with a more straightforward API for tasks like feature extraction and signal processing. Magenta has a steeper learning curve and larger codebase, while Librosa is more lightweight and accessible for audio analysis tasks.

3,291

a library for audio and music analysis

Pros of aubio

  • Written in C, offering potentially faster performance for low-level audio processing tasks
  • Provides command-line tools for quick audio analysis without writing code
  • Supports a wider range of audio input formats natively

Cons of aubio

  • Less extensive documentation and fewer examples compared to librosa
  • Smaller community and fewer third-party resources available
  • Steeper learning curve for Python developers due to its C core

Code Comparison

librosa example:

import librosa
y, sr = librosa.load('audio.wav')
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

aubio example:

import aubio
source = aubio.source('audio.wav')
tempo = aubio.tempo("default", 1024, 512, source.samplerate)
beats = []
while True:
    samples, read = source()
    is_beat = tempo(samples)
    if is_beat:
        beats.append(tempo.get_last_s())
    if read < source.hop_size:
        break

Both libraries offer audio analysis capabilities, but librosa provides a more Pythonic interface with simpler function calls, while aubio requires more low-level control and setup.

C++ library for audio and music analysis, description and synthesis, including Python bindings

Pros of Essentia

  • Written in C++, offering better performance for computationally intensive tasks
  • Provides a wider range of audio analysis algorithms and features
  • Offers both C++ and Python interfaces, allowing for flexibility in usage

Cons of Essentia

  • Steeper learning curve due to its more complex architecture
  • Less extensive documentation compared to Librosa
  • Installation can be more challenging, especially on certain platforms

Code Comparison

Librosa:

import librosa

y, sr = librosa.load('audio.wav')
tempo, beat_frames = librosa.beat.beat_track(y=y, sr=sr)

Essentia:

import essentia.standard as es

audio = es.MonoLoader(filename='audio.wav')()
rhythm_extractor = es.RhythmExtractor2013()
bpm, beats, _, _, _ = rhythm_extractor(audio)

Both libraries offer similar functionality for basic audio analysis tasks, but Essentia provides more advanced features and algorithms. Librosa is generally easier to use and has better documentation, making it more accessible for beginners. Essentia, on the other hand, offers better performance and a wider range of features, making it suitable for more complex audio analysis projects.

Python Audio Analysis Library: Feature Extraction, Classification, Segmentation and Applications

Pros of pyAudioAnalysis

  • Offers higher-level audio analysis features like speaker diarization and music genre classification
  • Includes a command-line interface for easy use without programming
  • Provides pre-trained models for some audio classification tasks

Cons of pyAudioAnalysis

  • Less actively maintained compared to librosa
  • Smaller community and fewer contributors
  • More limited in terms of low-level audio processing capabilities

Code Comparison

pyAudioAnalysis example:

from pyAudioAnalysis import audioBasicIO
from pyAudioAnalysis import audioFeatureExtraction

[Fs, x] = audioBasicIO.read_audio_file("example.wav")
F, f_names = audioFeatureExtraction.stFeatureExtraction(x, Fs, 0.050*Fs, 0.025*Fs)

librosa example:

import librosa

y, sr = librosa.load("example.wav")
mfccs = librosa.feature.mfcc(y=y, sr=sr)
chroma = librosa.feature.chroma_stft(y=y, sr=sr)

Both libraries provide audio analysis capabilities, but librosa is more focused on low-level audio processing and feature extraction, while pyAudioAnalysis offers some higher-level analysis tools. librosa has a larger community and is more actively maintained, making it a better choice for general audio processing tasks. However, pyAudioAnalysis may be preferable for specific high-level audio analysis tasks or for users who prefer a command-line interface.

2,506

Data manipulation and transformation for audio signal processing, powered by PyTorch

Pros of torchaudio

  • Seamless integration with PyTorch ecosystem for deep learning tasks
  • GPU acceleration for faster processing of audio data
  • Extensive support for audio I/O, including various audio formats

Cons of torchaudio

  • Steeper learning curve for users not familiar with PyTorch
  • Less comprehensive set of traditional audio signal processing functions
  • Requires PyTorch as a dependency, which may be overkill for simpler projects

Code Comparison

librosa:

import librosa

y, sr = librosa.load('audio.wav')
mfccs = librosa.feature.mfcc(y=y, sr=sr, n_mfcc=13)

torchaudio:

import torchaudio

waveform, sample_rate = torchaudio.load('audio.wav')
mfcc_transform = torchaudio.transforms.MFCC(sample_rate=sample_rate, n_mfcc=13)
mfccs = mfcc_transform(waveform)

Both libraries offer functionality for loading audio files and extracting MFCCs, but torchaudio's implementation is more tightly integrated with PyTorch tensors and can leverage GPU acceleration when available.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

librosa logo

librosa

A python package for music and audio analysis.

PyPI Anaconda-Server Badge License DOI

CI codecov Docs

Table of Contents


Documentation

See https://librosa.org/doc/ for a complete reference manual and introductory tutorials.

The advanced example gallery should give you a quick sense of the kinds of things that librosa can do.


Back To Top ↥

Installation

Using PyPI

The latest stable release is available on PyPI, and you can install it by saying

python -m pip install librosa

Using Anaconda

Anaconda users can install using conda-forge:

conda install -c conda-forge librosa

Building from source

To build librosa from source, say

python setup.py build

Then, to install librosa, say

python setup.py install

If all went well, you should be able to execute the following commands from a python console:

import librosa
librosa.show_versions()

This should print out a description of your software environment, along with the installed versions of other packages used by librosa.

📝 OS X users should follow the installation guide given below.

Alternatively, you can download or clone the repository and use pip to handle dependencies:

unzip librosa.zip
python -m pip install -e librosa

or

git clone https://github.com/librosa/librosa.git
python -m pip install -e librosa

By calling pip list you should see librosa now as an installed package:

librosa (0.x.x, /path/to/librosa)

Back To Top ↥

Hints for the Installation

librosa uses soundfile and audioread to load audio files.

📝 Note that older releases of soundfile (prior to 0.11) do not support MP3, which will cause librosa to fall back on the audioread library.

soundfile

If you're using conda to install librosa, then audio encoding dependencies will be handled automatically.

If you're using pip on a Linux environment, you may need to install libsndfile manually. Please refer to the SoundFile installation documentation for details.

audioread and MP3 support

To fuel audioread with more audio-decoding power (e.g., for reading MP3 files), you may need to install either ffmpeg or GStreamer.

📝Note that on some platforms, audioread needs at least one of the programs to work properly.

If you are using Anaconda, install ffmpeg by calling

conda install -c conda-forge ffmpeg

If you are not using Anaconda, here are some common commands for different operating systems:

  • Linux (apt-get):

apt-get install ffmpeg

or

apt-get install gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly
  • Linux (yum):

yum install ffmpeg

or

yum install gstreamer1.0-plugins-base gstreamer1.0-plugins-ugly
  • Mac:

brew install ffmpeg

or

brew install gstreamer
  • Windows:

download ffmpeg binaries from this website or gstreamer binaries from this website

For GStreamer, you also need to install the Python bindings with

python -m pip install pygobject

Back To Top ↥

Discussion

Please direct non-development questions and discussion topics to our web forum at https://groups.google.com/forum/#!forum/librosa


Back To Top ↥

Citing

If you want to cite librosa in a scholarly work, there are two ways to do it.

  • If you are using the library for your work, for the sake of reproducibility, please cite the version you used as indexed at Zenodo:

    DOI

    From librosa version 0.10.2 or later, you can also use librosa.cite() to get the DOI link for any version of librosa.

  • If you wish to cite librosa for its design, motivation, etc., please cite the paper published at SciPy 2015:

    McFee, Brian, Colin Raffel, Dawen Liang, Daniel PW Ellis, Matt McVicar, Eric Battenberg, and Oriol Nieto. "librosa: Audio and music signal analysis in python." In Proceedings of the 14th python in science conference, pp. 18-25. 2015.


Back To Top ↥