๐Ÿ 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 y์™€ sampling 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)

๋ฐ˜์‘ํ˜•