speechbrain.processing.signal_processing 模块
低级信号处理工具
- Authors
彼得·普兰廷加 2020
弗朗索瓦·格隆丹 2020
威廉·阿里斯 2020
萨穆埃莱·科内尔 2020
Sarthak Yadav 2022
摘要
函数:
计算一批波形的振幅。 |
|
使用 torch.nn.functional 执行一维填充和卷积。 |
|
返回从分贝转换而来的振幅比。 |
|
用于生成GaborConv1d中使用的Gabor脉冲响应的函数 |
|
用于生成Gabor脉冲响应的函数,但不使用GaborConv1d中提出的complex64数据类型 |
|
此函数对输入的均值和标准差进行归一化 |
|
此函数将信号归一化为单位平均值或峰值幅度。 |
|
返回由高通滤波器和低通滤波器构建的陷波滤波器。 |
|
取自 https://github.com/kaituoxu/Conv-TasNet/blob/master/src/utils.py |
|
此函数执行信号重新缩放到目标级别。 |
|
用于从增强的幅度重新合成波形的函数。 |
|
通用函数,用于通过给定的房间脉冲响应(RIR)对给定信号进行混响污染。 |
参考
- speechbrain.processing.signal_processing.compute_amplitude(waveforms, lengths=None, amp_type='avg', scale='linear')[source]
计算一批波形的振幅。
- Parameters:
- Return type:
波形的平均振幅。
Example
>>> signal = torch.sin(torch.arange(16000.0)).unsqueeze(0) >>> compute_amplitude(signal, signal.size(1)) tensor([[0.6366]])
- speechbrain.processing.signal_processing.normalize(waveforms, lengths=None, amp_type='avg', eps=1e-14)[source]
此函数将信号归一化为单位平均值或峰值幅度。
- speechbrain.processing.signal_processing.mean_std_norm(waveforms, dims=1, eps=1e-06)[source]
- This function normalizes the mean and std of the input
波形(沿指定轴)。
- speechbrain.processing.signal_processing.rescale(waveforms, lengths, target_lvl, amp_type='avg', scale='linear')[source]
此函数执行信号重新缩放到目标级别。
- Parameters:
- Returns:
波形 – 重新调整的波形。
- Return type:
张量
- speechbrain.processing.signal_processing.convolve1d(waveform, kernel, padding=0, pad_type='constant', stride=1, groups=1, use_fft=False, rotation_index=0)[source]
使用 torch.nn.functional 执行一维填充和卷积。
- Parameters:
波形 (张量) – 要执行操作的张量。
kernel (tensor) – 在卷积过程中应用的过滤器。
padding (int 或 tuple) – 要应用的填充(pad_left, pad_right)。 如果传递的是整数,则将其传递给 conv1d 函数,并忽略 pad_type。
pad_type (str) – 使用的填充类型。直接传递给
torch.nn.functional.pad
,请参阅 PyTorch 文档 以了解可用的选项。stride (int) – 每次应用卷积时移动的单位数。 传递给 conv1d。如果
use_fft
为 True,则无效。groups (int) – 此选项传递给
conv1d
以将输入分成组进行卷积。输入通道应能被组数整除。use_fft (bool) – 当
use_fft
传递True
时,则在频谱域中使用复数乘法计算卷积。这在CPU上当内核大小较大时(例如混响)更高效。警告:如果没有填充,会发生循环卷积。这在混响的情况下影响不大,但在使用不同内核时可能会有更大的差异。rotation_index (int) – 此选项仅在
use_fft
为真时适用。如果是这样,卷积前内核会按此量滚动以移动输出位置。
- Return type:
卷积后的波形。
Example
>>> from speechbrain.dataio.dataio import read_audio >>> signal = read_audio('tests/samples/single-mic/example1.wav') >>> signal = signal.unsqueeze(0).unsqueeze(2) >>> kernel = torch.rand(1, 10, 1) >>> signal = convolve1d(signal, kernel, padding=(9, 0))
- speechbrain.processing.signal_processing.reverberate(waveforms, rir_waveform, rescale_amp='avg')[source]
通用函数,用于使用给定的房间脉冲响应(RIR)对给定信号进行混响污染。 它在RIR和信号之间执行卷积,但不改变信号的原始振幅。
- Parameters:
波形 (张量) – 需要标准化的波形。 形状应为
[batch, time]
或[batch, time, channels]
。rir_waveform (tensor) – RIR 张量,形状应为 [时间, 通道]。
rescale_amp (str) – 是否对混响信号进行重新缩放(None),并且相对于原始信号的“峰值”振幅或“平均”振幅。 在 [None, “avg”, “peak”] 之间选择。
- Returns:
波形 – 混响信号。
- Return type:
张量
- speechbrain.processing.signal_processing.dB_to_amplitude(SNR)[source]
返回从分贝转换而来的振幅比。
- Parameters:
SNR (float) – 要转换的分贝比。
- Return type:
振幅比
Example
>>> round(dB_to_amplitude(SNR=10), 3) 3.162 >>> dB_to_amplitude(SNR=0) 1.0
- speechbrain.processing.signal_processing.notch_filter(notch_freq, filter_width=101, notch_width=0.05)[source]
返回由高通滤波器和低通滤波器构建的陷波滤波器。
(来自 https://tomroelandts.com/articles/ 如何创建简单的带通和带阻滤波器)
- Parameters:
- Return type:
计算出的过滤器
Example
>>> from speechbrain.dataio.dataio import read_audio >>> signal = read_audio('tests/samples/single-mic/example1.wav') >>> signal = signal.unsqueeze(0).unsqueeze(2) >>> kernel = notch_filter(0.25) >>> notched_signal = convolve1d(signal, kernel)
- speechbrain.processing.signal_processing.overlap_and_add(signal, frame_step)[source]
取自 https://github.com/kaituoxu/Conv-TasNet/blob/master/src/utils.py
从帧表示中重建信号。 将形状为
[..., frames, frame_length]
的信号的可能重叠帧相加,通过frame_step
偏移后续帧。 结果张量的形状为[..., output_size]
,其中输出大小 = (帧数 - 1) * 帧步长 + 帧长度
- Parameters:
signal (A [..., frames, frame_length] torch.Tensor.) – 所有维度可能未知,且秩必须至少为2。
frame_step (int) – 一个表示重叠偏移量的整数。必须小于或等于frame_length。
- Returns:
一个形状为[…, output_size]的张量,包含信号最内层两个维度的重叠添加帧。 – output_size = (frames - 1) * frame_step + frame_length
基于 https (//github.com/tensorflow/tensorflow/blob/r1.12/tensorflow/contrib/signal/python/ops/reconstruction_ops.py)
Example
>>> signal = torch.randn(5, 20) >>> overlapped = overlap_and_add(signal, 20) >>> overlapped.shape torch.Size([100])
- speechbrain.processing.signal_processing.resynthesize(enhanced_mag, noisy_inputs, stft, istft, normalize_wavs=True)[source]
用于从增强的幅度重新合成波形的函数。
- Parameters:
enhanced_mag (torch.Tensor) – 预测的频谱幅度,应该是三维的。
noisy_inputs (torch.Tensor) – 任何处理前的噪声波形,用于提取相位。
stft (torch.nn.Module) – 用于计算STFT以提取相位的模块。
istft (torch.nn.Module) – 用于计算iSTFT以进行重新合成的模块。
normalize_wavs (bool) – 是否在返回之前对输出的wav文件进行归一化处理。
- Returns:
enhanced_wav – 使用噪声相位增强幅度的重新合成波形。
- Return type:
torch.Tensor
- speechbrain.processing.signal_processing.gabor_impulse_response(t, center, fwhm)[source]
用于生成Gabor脉冲响应的函数 如GaborConv1d所提出的
Neil Zeghidour, Olivier Teboul, F{‘e}lix de Chaumont Quitry & Marco Tagliasacchi, “LEAF: 一种可学习的音频分类前端”, 在ICLR 2021的会议论文中 (https://arxiv.org/abs/2101.08596)
- speechbrain.processing.signal_processing.gabor_impulse_response_legacy_complex(t, center, fwhm)[source]
用于生成Gabor脉冲响应的函数,但不使用GaborConv1d中提出的complex64数据类型
Neil Zeghidour, Olivier Teboul, F{‘e}lix de Chaumont Quitry & Marco Tagliasacchi, “LEAF: 一种可学习的音频分类前端”, 在ICLR 2021的会议论文中 (https://arxiv.org/abs/2101.08596)