当前位置:网站首页>Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
Recognize the small experiment of extracting and displaying Mel spectrum (observe the difference between different y_axis and x_axis)
2022-07-06 00:01:00 【Begonia_ cat】
Import librosa
import librosa
Read audio
y, sr = librosa.load("C:/Users/24061/Desktop/MER Data sets /DEAM/DEAM_audio/MEMD_audio_wav/2.wav")
y
array([0. , 0. , 0. , ..., 0.4163208 , 0.43338013,
0.40551758], dtype=float32)
sr
22050
Extract Mel spectrum
mel_spectrogram = librosa.feature.melspectrogram(y=y, sr=sr, n_fft=2048, hop_length=1024)
mel_spectrogram # type: numpy.ndarray
array([[0.00000000e+00, 1.25761675e-02, 2.62945890e+00, ...,
4.08293676e+00, 7.79196739e+00, 5.92219353e+00],
[0.00000000e+00, 1.00206733e-01, 1.33076525e+00, ...,
6.49990678e-01, 1.44000304e+00, 1.67580545e+00],
[0.00000000e+00, 4.64823037e-01, 1.54586525e+01, ...,
3.54503012e+00, 2.53890848e+00, 9.59981441e+00],
...,
[0.00000000e+00, 6.95451519e-09, 3.43443826e-05, ...,
6.05733460e-03, 1.72329806e-02, 7.06060929e-03],
[0.00000000e+00, 7.65795605e-09, 7.63881962e-06, ...,
1.81941327e-03, 3.55470460e-03, 4.70093498e-03],
[0.00000000e+00, 4.74458783e-09, 5.26388646e-07, ...,
1.27859021e-04, 7.03962069e-05, 1.91266462e-03]], dtype=float32)
mel_spectrogram.shape
(128, 971)
Show Mel spectrum
1、 When not converted to logarithmic spectrum
- Display frequency on mel scale
y_axis='mel'
import librosa.display
librosa.display.specshow(mel_spectrogram, y_axis='mel', x_axis='time')
<matplotlib.collections.QuadMesh at 0x23d902a60b8>
- Display frequency on logarithmic scale
y_axis='log'
librosa.display.specshow(mel_spectrogram, y_axis='log', x_axis='time')
<matplotlib.collections.QuadMesh at 0x23d92827e80>
2、 Convert the amplitude to logarithm
mel_spectrogram_db = librosa.amplitude_to_db(mel_spectrogram)
mel_spectrogram_db
array([[-19.654686 , -19.654686 , 8.397327 , ..., 12.219453 ,
17.832943 , 15.449652 ],
[-19.654686 , -19.654686 , 2.482029 , ..., -3.7418575,
3.167268 , 4.484472 ],
[-19.654686 , -6.6542473, 23.783434 , ..., 10.992398 ,
8.092941 , 19.645256 ],
...,
[-19.654686 , -19.654686 , -19.654686 , ..., -19.654686 ,
-19.654686 , -19.654686 ],
[-19.654686 , -19.654686 , -19.654686 , ..., -19.654686 ,
-19.654686 , -19.654686 ],
[-19.654686 , -19.654686 , -19.654686 , ..., -19.654686 ,
-19.654686 , -19.654686 ]], dtype=float32)
mel_spectrogram_db.shape
(128, 971)
- Display frequency on mel scale
y_axis="mel"
librosa.display.specshow(mel_spectrogram_db, y_axis="mel",x_axis="time" )
<matplotlib.collections.QuadMesh at 0x23d9194ce10>
- Display frequency on logarithmic scale
y_axis="log"
librosa.display.specshow(mel_spectrogram_db, y_axis="log",x_axis="time" )
<matplotlib.collections.QuadMesh at 0x23d925c7cc0>
With Hz Display frequency y_axis="hz"
librosa.display.specshow(mel_spectrogram_db, y_axis="hz",x_axis="time" )
<matplotlib.collections.QuadMesh at 0x23d92c2f5f8>
- Show the frequency in logarithmic spectrum
y_axis="log"
, The unit of time is secondsx_axis="s"
librosa.display.specshow(mel_spectrogram_db, y_axis="log",x_axis="s" )
<matplotlib.collections.QuadMesh at 0x23d9348a550>
- Show the frequency in logarithmic spectrum
y_axis="log"
, Time is measured in millisecondsx_axis="ms"
librosa.display.specshow(mel_spectrogram_db, y_axis="log",x_axis="ms" )
<matplotlib.collections.QuadMesh at 0x23d93ea76a0>
rhythm ( To be continued ), I don't quite understand
librosa.feature.fourier_tempogram(y, sr)
C:\Users\24061\anaconda3\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: Pass y=[0. 0. 0. ... 0.4163208 0.43338013 0.40551758], sr=22050 as keyword args. From version 0.10 passing these as positional arguments will result in an error
"""Entry point for launching an IPython kernel.
array([[ 1.41953934e+02+0.0000000e+00j, 1.43232498e+02+0.0000000e+00j,
1.44507858e+02+0.0000000e+00j, ...,
1.20833031e+02+0.0000000e+00j, 1.19599785e+02+0.0000000e+00j,
1.18365807e+02+0.0000000e+00j],
[-8.12093430e+01+7.8693253e+01j, -8.25004044e+01+7.8347717e+01j,
-8.37830200e+01+7.7980965e+01j, ...,
-6.11498871e+01-7.6005348e+01j, -5.98955841e+01-7.6018913e+01j,
-5.86419067e+01-7.6011627e+01j],
[ 2.08344612e+01-5.4645943e+01j, 2.22085571e+01-5.3934937e+01j,
2.35550823e+01-5.3178368e+01j, ...,
1.26519930e+00+5.0331814e+01j, 4.82287928e-02+5.0350494e+01j,
-1.16933417e+00+5.0330265e+01j],
...,
[-3.68897580e-02-7.4101496e-01j, 9.78471190e-02+7.0739186e-01j,
-1.57261893e-01-6.6958255e-01j, ...,
-4.85646218e-01+1.2208136e-01j, 4.81895536e-01-1.4795184e-01j,
-4.76868808e-01+1.7341925e-01j],
[-1.62224078e+00-6.7166932e-02j, 1.64763165e+00+3.6856860e-02j,
-1.67323339e+00-5.3153611e-03j, ...,
6.40185595e-01-6.1752874e-01j, -6.37307167e-01+6.1541033e-01j,
6.34444416e-01-6.1347997e-01j],
[ 1.42917812e+00+0.0000000e+00j, -1.40549254e+00+0.0000000e+00j,
1.38058436e+00+0.0000000e+00j, ...,
-1.41562808e+00+0.0000000e+00j, 1.39833307e+00+0.0000000e+00j,
-1.38108861e+00+0.0000000e+00j]], dtype=complex64)
librosa.display.specshow(librosa.amplitude_to_db(librosa.feature.fourier_tempogram(y, sr)))
C:\Users\24061\anaconda3\envs\tensorflow\lib\site-packages\ipykernel_launcher.py:1: FutureWarning: Pass y=[0. 0. 0. ... 0.4163208 0.43338013 0.40551758], sr=22050 as keyword args. From version 0.10 passing these as positional arguments will result in an error
"""Entry point for launching an IPython kernel.
C:\Users\24061\anaconda3\envs\tensorflow\lib\site-packages\librosa\util\decorators.py:88: UserWarning: amplitude_to_db was called on complex input so phase information will be discarded. To suppress this warning, call amplitude_to_db(np.abs(S)) instead.
return f(*args, **kwargs)
<matplotlib.collections.QuadMesh at 0x23d9325f860>
边栏推荐
- Qt 一个简单的word文档编辑器
- How to rotate the synchronized / refreshed icon (EL icon refresh)
- 用列表初始化你的vector&&initializer_list简介
- Determinant learning notes (I)
- There is no network after configuring the agent by capturing packets with Fiddler mobile phones
- C# 文件与文件夹操作
- Zero rhino technology joined hands with the intelligence Club: the "causal faction" forum was successfully held, and the "causal revolution" brought the next generation of trusted AI
- Transport layer protocol ----- UDP protocol
- QT--线程
- 跟着CTF-wiki学pwn——ret2libc1
猜你喜欢
Bao Yan notes II software engineering and calculation volume II (Chapter 13-16)
XML configuration file (DTD detailed explanation)
XML配置文件(DTD详细讲解)
[noi simulation] Anaid's tree (Mobius inversion, exponential generating function, Ehrlich sieve, virtual tree)
Zhongjun group launched electronic contracts to accelerate the digital development of real estate enterprises
PV static creation and dynamic creation
How to rotate the synchronized / refreshed icon (EL icon refresh)
零犀科技携手集智俱乐部:“因果派”论坛成功举办,“因果革命”带来下一代可信AI
Single merchant v4.4 has the same original intention and strength!
C reflection and type
随机推荐
The difference of time zone and the time library of go language
Research notes I software engineering and calculation volume II (Chapter 1-7)
[EF core] mapping relationship between EF core and C data type
云呐|公司固定资产管理系统有哪些?
My colleagues quietly told me that flying Book notification can still play like this
[online chat] the original wechat applet can also reply to Facebook homepage messages!
多普勒效應(多普勒頻移)
用列表初始化你的vector&&initializer_list简介
Add noise randomly to open3d point cloud
Online yaml to CSV tool
用列錶初始化你的vector&&initializer_list簡介
FFT 学习笔记(自认为详细)
Doppler effect (Doppler shift)
18. (ArcGIS API for JS) ArcGIS API for JS point collection (sketchviewmodel)
行列式学习笔记(一)
【QT】Qt使用QJson生成json文件并保存
14 MySQL view
FFMPEG关键结构体——AVFrame
【SQL】各主流数据库sql拓展语言(T-SQL 、 PL/SQL、PL/PGSQL)
权限问题:source .bash_profile permission denied