【librosa】及其在音频处理中的应用
【持续更新】
为了简便:import librosa
display
specshow (data[, x_coords, y_coords, x_axis, …]) |
Display a spectrogram/chromagram/cqt/etc. |
waveplot (y[, sr, max_points, x_axis, …]) |
Plot the amplitude envelope of a waveform. |
cmap (data[, robust, cmap_seq, cmap_bool, …]) |
Get a default colormap from the given data. |
TimeFormatter ([lag, unit]) |
A tick formatter for time axes. |
NoteFormatter ([octave, major]) |
Ticker formatter for Notes |
LogHzFormatter ([major]) |
Ticker formatter for logarithmic frequency |
ChromaFormatter |
A formatter for chroma axes |
TonnetzFormatter |
A formatter for tonnetz axes |
[1]中介绍了很多关于librosa的应用,同时提出librosa.display模块并不默认包含在librosa中,使用时要单独引入:
import librosa.display
waveplot
Plot the amplitude envelope of a waveform.
If y is monophonic, a filled curve is drawn between [-abs(y), abs(y)].
If y is stereo, the curve is drawn between [-abs(y[1]), abs(y[0])], so that the left and right channels are drawn above and below the axis, respectively.
Long signals (duration >= max_points) are down-sampled to at most max_sr before plotting.
librosa.display.waveplot(y, sr=22050, max_points=50000.0, x_axis='time', offset=0.0, max_sr=1000, ax=None, **kwargs)
specshow
Display a spectrogram/chromagram/cqt/etc.
librosa.display.specshow(data, x_coords=None, y_coords=None, x_axis=None, y_axis=None, sr=22050, hop_length=512, fmin=None, fmax=None, tuning=0.0, bins_per_octave=12, ax=None, **kwargs)
注意:源码中 sr 默认是22050Hz,如果音频文件是8k或者16k,一定要指定采样率。
可以选择不同的尺度显示频谱图,y_axis={‘linear’, ‘log’, ‘mel’, ‘cqt_hz’,...}
stft / istft
短时傅里叶变换 / 逆短时傅里叶变换,参考librosa源码和博客[librosa语音信号处理]。
librosa.stft(y, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, pad_mode='reflect')
librosa.core.stft(y, n_fft=2048, hop_length=None, win_length=None, window='hann', center=True, dtype=<class 'numpy.complex64'>, pad_mode='reflect') # This function caches at level 20.
The STFT represents a signal in the time-frequency domain by computing discrete Fourier transforms (DFT) over short overlapping windows. This function returns a complex-valued matrix D such that
- np.abs(D[f, t]) is the magnitude of frequency bin f at frame t, and
- np.angle(D[f, t]) is the phase of frequency bin f at frame t.
Parameters: |
|
---|---|
Returns: |
|
librosa.istft(stft_matrix, hop_length=None, win_length=None, window='hann', center=True, length=None)
librosa.core.istft(stft_matrix, hop_length=None, win_length=None, window='hann', center=True, dtype=<class 'numpy.float32'>, length=None) # This function caches at level 30.
Converts a complex-valued spectrogram stft_matrix to time-series y by minimizing the mean squared error between stft_matrix and STFT of y as described in [2] up to Section 2 (reconstruction from MSTFT).
In general, window function, hop length and other parameters should be same as in stft, which mostly leads to perfect reconstruction of a signal from unmodified stft_matrix.
Parameters: |
|
---|---|
Returns: |
|
有用的函数
effects.split
librosa.effects.split(y, top_db=60, ref=<function amax at 0x7fa274a61d90>, frame_length=2048, hop_length=512)
Split an audio signal into non-silent intervals. 参数说明源码。
Parameters: |
|
---|---|
Returns: |
|
参考
[1] https://www.cnblogs.com/xingshansi/p/6816308.html
[2] D. W. Griffin and J. S. Lim, “Signal estimation from modified short-time Fourier transform,” IEEE Trans. ASSP, vol.32, no.2, pp.236–243, Apr. 1984.
【librosa】及其在音频处理中的应用的更多相关文章
- 音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系
音频采样中left-or right-justified(左对齐,右对齐), I2S时钟关系 原创 2014年02月11日 13:56:51 4951 0 0 刚刚过完春节,受假期综合症影响脑袋有点发 ...
- 音频处理中的尺度--Bark尺度与Mel尺度
由于人耳对声音的感知(如:频率.音调)是非线性的,为了对声音的感知进行度量,产生了一系列的尺度(如:十二平均律),这里重点说下Bark尺度与Mel尺度.刚开始的时候,我自己也没弄明白这两个尺度的区别. ...
- AEC、AGC、ANS在视音频会议中的作用?
AGC是自动增益补偿功能(Automatic Gain Control),AGC可以自动调麦克风的收音量,使与会者收到一定的音量水平,不会因发言者与麦克风的距离改变时,声音有忽大忽小声的缺点.ANS是 ...
- 数据处理一条龙!这15个Python库不可不知
如果你是一名数据科学家或数据分析师,或者只是对这一行业感兴趣,那下文中这些广受欢迎且非常实用的Python库你一定得知道. 从数据收集.清理转化,到数据可视化.图像识别和网页相关,这15个Python ...
- 测试开发之前端——No9.HTML5中的视频/音频
HTML5 视频和音频的 DOM 参考手册 HTML5 DOM 为 <audio> 和 <video> 元素提供了方法.属性和事件. 这些方法.属性和事件允许您使用 JavaS ...
- 音频中PCM的概念
本文取自由http://blog.csdn.net/droidphone一部分 1. PCM是什么 PCM是英文Pulse-code modulation的缩写,中文译名是脉冲编码调制.我们知道在现实 ...
- html5中audio支持音频格式
HTML5 Audio标签能够支持wav, mp3, ogg, acc, webm等格式,但有个很重要的音乐文件格式midi(扩展名mid)却在各大浏览器中都没有内置的支持.不是所有的浏览器都支持MP ...
- librosa语音信号处理
librosa是一个非常强大的python语音信号处理的第三方库,本文参考的是librosa的官方文档,本文主要总结了一些重要,对我来说非常常用的功能.学会librosa后再也不用用python去实现 ...
- WAVE音频格式及及转换代码
音频信号的读写.播放及录音 python已经支持WAV格式的书写,而实时的声音输入输出需要安装pyAudio(http://people.csail.mit.edu/hubert/pyaudio).最 ...
随机推荐
- 程序员需要了解的linux常用命令
网络 找出某程序(tomcat)的进程 ps -ef|grep tomcat 找出后如果要关闭 kill -9 pid统计某程序(tomcat)连接数 ps -ef|grep tomcat|w ...
- PHP for的1个问题
PHP for的1个问题 <pre><?php for ($k = 13; $k > 0; $k--) { echo 'wef'; }?></pre>ps: ...
- c++小学期大作业攻略(零)建议+代码结构(持续更新)
当前已经做好的exe,数据库是连服务器的,但是头像是存在本地的文件系统里面: https://cloud.tsinghua.edu.cn/d/059ef6b1f9a149ce879b/files/?p ...
- Centos7.5 安装Mysql5.7
#yum -y install wget #wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rp ...
- 订单1:n支付单 设计讨论
方法一:订单1:1支付单,下单时生成1订单,并生成1支付单(这个支付单是微信需要的相关信息),设置超时时间2小时,如果订单超时,则提示用户,订单已超时,重新下单即可: 方法二:订单1:N支付单,下单时 ...
- Thinkpad S430 3364-A59 (笔记本型号)加内存条过程
背景:13年初选购的本,目前使用发现卡得厉害,原装内存只有4G,遂寻思扩充内存. [1]准备工具 待准备工具明细: (1)螺丝刀 主要为了卸后盖的螺丝. (2)内存条 待增加的内存条,如下图: 说明一 ...
- Java学习:注解简介
JAVA 注解的基本原理 以前,『XML』是各大框架的青睐者,它以松耦合的方式完成了框架中几乎所有的配置,但是随着项目越来越庞大,『XML』的内容也越来越复杂,维护成本变高. 于是就有人提出来一种标记 ...
- JavaIO学习:字符流
JavaIO流之字符流 字符流 Reader InputStreamReader FileReader:专门用于处理文件的字符读取流对象. Writer OutputStreamWriter File ...
- 分布式任务调度平台XXL-JOB快速使用与问题总结
1.XXL-JOB简介 XXL-JOB is a lightweight distributed task scheduling framework. It's core design goal is ...
- Java反射获取泛型类型
本文链接:https://blog.csdn.net/hongxingxiaonan/article/details/49202613 在Java反射技术的应用中,取得一个类的成员.方法和构造函数相对 ...