Below is a code example. The input test file is found at https://github.com/jonnor/machinehearing/blob/ab7fe72807e9519af0151ec4f7ebfd890f432c83/handson/spectrogram-inversion/436951__arnaud-coutancier__old-ladies-pets-and-train-02.flacimport numpyimport librosaimport soundfile# parameterssr = 22050n_mels = 128hop_length = 512n_iter = 32n_mfcc = None # can try n_mfcc=20# load audio and create Mel-spectrogrampath = '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 additionif 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-spectrogramS_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)结果重构后的波形会有一些伪像.ResultsThe reconstructed waveform will have some artifacts.上面的示例重复出现了很多噪音,超出了我的预期.使用Audacity中的标准降噪算法可以将其降低很多.The above example got a lot of repetitive noise, more than I expected. It was possible to reduce it quite a lot using the standard Noise Reduction algorithm in Audacity. 这篇关于从FFT数据创建波形数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 01:09