🐍 Python & library/librosa

[Librosa] music/audio processing library Librosa 사용법 Tutorial - (1) install, import and load

복만 2021. 9. 23. 15:58

Librosa는 music/audio data의 처리를 위해 사용되는 library이다.

이번학기 수업에서 사용하게 되어 사용법을 정리해보려고 한다.

Official docs: https://librosa.org/doc/main/index.html

 

librosa — librosa 0.8.1 documentation

© Copyright 2013--2021, librosa development team.

librosa.org

 

music/audio processing library Librosa 사용법 Tutorial 

(1) Install, import and load

(2) Audio data representations (Spectogram, Mel-spectogram)

(3) Audio feature extraction

(4) Audio feature processing

 

 

 

Install & Load librosa

다음과 같이 librosa library를 설치하고, 불러올 수 있다.

pip install librosa
import librosa

 

 

 

Load audio file

다음과 같이 audio file을 불러올 수 있다.

librosa에서 제공하는 example audio file을 사용해도 되고, 직접 audio file을 불러와도 된다.

filename = librosa.exampe('nutcracker')

y, sr = librosa.load(filename)

 

example audio file들은 아래 링크에서 확인할 수 있다.

https://librosa.org/doc/main/recordings.html

 

Example files — librosa 0.8.1 documentation

Example files librosa includes a small selection of example recordings which are primarily used to demonstrate different functions of the library. Beginning with version 0.8, these examples are automatically retrieved from a remote server upon request. Exa

librosa.org

 

librosa.load method는 audio file에서 waveform ysampling rate sr을 불러온다.
y는 1차원 numpy float array이다.
sr은 초당 sample의 수를 의미하며, default 값은 22050Hz이다.

load method에 argument를 추가해 sampling rate를 재설정할 수도 있다.

 

librosa.display를 이용하면 waveform을 시각화할 수 있다.

import librosa.display

librosa.display.waveplot(y, sr=sr)

반응형