Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 |
Tags
- PyMOL
- 파이몰
- 리간드
- 단백질
- 생물정보학
- 프로그램
- python
- 분비단백질
- RMSD
- 파이썬
- python3
- imgaemagick
- transmembrane
- overflowed
- python2
- in planta
- ab initio
- perl
- purification
- 소리분석
- R
- dtw
- protein
- 3차원구조
- 파이썬3
- portaudio
- librosa
- pyaudio
- bioinformatics
- venn
Archives
- Today
- Total
박사면뭐해
파이썬3 librosa 라이브러리를 이용한 소리 파일(.wav) 비교 본문
사무실을 비웠을 때, 사무실로 전화가 오면 스마트폰으로 착신이 되게하고 싶었다.
그러나, 알아보니 착신 기능은 전화국에 별도로 요금을 내고 신청이 필요하다고 한다.
(전화국이란게 지금도 있나 싶지만?)
대신, 전화기가 발신자 정보표시를 보여주는 LCD를 가지고 있어,
라즈베리파이 프로젝트로 전화소리가 울리면 LCD 화면을 캡쳐해주고
사진을 스마트폰으로 보내주는 서버를 만들기로 했다.
이를 위해 가장 먼저 필요한 것은 소리 전화소리를 구분할 수 있는 코드를 짜는 것 이였다.
역시 파이썬은 필요한 패키지가 검색하면 나온다.
librosa는 음악 및 오디오 분석을 위한 파이썬 패키지이다.
이 패키지를 사용하여 wav 사운드파일을 비교 분석한 코드를 공유한다.
import librosa
import matplotlib.pyplot as plt
from dtw import dtw
from numpy.linalg import norm
#Loading audio files
y1, sr1 = librosa.load('ring_query.wav')
y2, sr2 = librosa.load('ring_target.wav')
#Showing multiple plots using subplot
plt.subplot(1, 2, 1)
mfcc1 = librosa.feature.mfcc(y1,sr1) #Computing MFCC values
librosa.display.specshow(mfcc1)
plt.subplot(1, 2, 2)
mfcc2 = librosa.feature.mfcc(y2, sr2)
librosa.display.specshow(mfcc2)
dist, cost, acc_cost, path = dtw(mfcc1.T, mfcc2.T, dist=lambda x, y: norm(x - y, ord=1))
print('Normalized distance between the two sounds:', dist)
※ matplotlib와 관련된 코드는 그림으로 소리를 비교하기 위한 것이라 주석 처리를 해도 된다.
중요한 것은 두 사운드 파일 간 거리를 dtw로 계산하여 dist로 주는 것이다.
dist가 0에 가까울수록 두 소리가 비슷한 것이다.
출처:
https://github.com/d4r3topk/comparing-audio-files-python/blob/master/mfcc.py
https://github.com/pierre-rouanet/dtw/blob/master/examples/MFCC%20%2B%20DTW.ipynb
Comments