hnd*_*ndr 3 python signal-processing fft spectrogram mfcc
正如您可能注意到的,我对 python 和声音处理非常陌生。我(希望)使用 python 以及 logfbank 和 mfcc 函数从波形文件中提取 FFT 数据。(logfbank 似乎提供了最有希望的数据,mfcc 输出对我来说看起来有点奇怪)。
在我的程序中,我想更改 logfbank/mfcc 数据,然后从中创建波形数据(并将它们写入文件中)。我确实没有找到任何有关从 FFT 数据创建波形数据的过程的信息。你们中有人知道如何解决这个问题吗?我将非常感激:)
到目前为止,这是我的代码:
from scipy.io import wavfile
import numpy as np
from python_speech_features import mfcc, logfbank
rate, signal = wavfile.read('orig.wav')
fbank = logfbank(signal, rate, nfilt=100, nfft=1400).T
mfcc = mfcc(signal, rate, numcep=13, nfilt=26, nfft=1103).T
#magic data processing of fbank or mfcc here
#creating wave data and writing it back to a .wav file here
Run Code Online (Sandbox Code Playgroud)
包含幅度和相位的适当构建的 STFT 频谱图可以使用重叠相加方法转换回时域波形。重要的是,频谱图构造必须具有恒定重叠相加属性。
让您的修改正确地操纵频谱图的幅度和相位可能具有挑战性。因此有时相位会被丢弃,而幅度会被独立操纵。为了将其转换回波形,必须在重建期间估计相位信息(相位重建)。这是一个有损过程,并且通常计算量很大。既定方法使用迭代算法,通常是 Griffin-Lim 的变体。但现在也有使用卷积神经网络的新方法。
librosa 版本 0.7.0包含快速 Griffin-Lim 实现以及用于反转 MFCC 梅尔谱图的辅助函数。
import numpy
import librosa
import soundfile
# parameters
sr = 22050
n_mels = 128
hop_length = 512
n_iter = 32
n_mfcc = None # can try n_mfcc=20
# load audio and create Mel-spectrogram
path = '436951__arnaud-coutancier__old-ladies-pets-and-train-02.flac'
y, _ = librosa.load(path, sr=sr)
S = numpy.abs(librosa.stft(y, hop_length=hop_length, n_fft=hop_length*2))
mel_spec = librosa.feature.melspectrogram(S=S, sr=sr, n_mels=n_mels, hop_length=hop_length)
# optional, compute MFCCs in addition
if n_mfcc is not None:
mfcc = librosa.feature.mfcc(S=librosa.power_to_db(S), sr=sr, n_mfcc=n_mfcc)
mel_spec = librosa.feature.inverse.mfcc_to_mel(mfcc, n_mels=n_mels)
# Invert mel-spectrogram
S_inv = librosa.feature.inverse.mel_to_stft(mel_spec, sr=sr, n_fft=hop_length*4)
y_inv = librosa.griffinlim(S_inv, n_iter=n_iter,
hop_length=hop_length)
soundfile.write('orig.wav', y, samplerate=sr)
soundfile.write('inv.wav', y_inv, samplerate=sr)
Run Code Online (Sandbox Code Playgroud)
重建的波形会有一些伪影。
上面的例子有很多重复的噪音,超出了我的预期。使用 Audacity 中的标准降噪算法可以将其降低很多。
| 归档时间: |
|
| 查看次数: |
2583 次 |
| 最近记录: |