繁体   English   中英

如何从 librosa 中的梅尔频谱图重建 STFT 矩阵,以便重建原始音频?

[英]How can I reconstruct the STFT matrix from a mel spectrogram in librosa so I reconstruct the original audio?

我使用以下代码在 librosa 中生成了一个 melspectrogram

import os
from matplotlib import pyplot as plt
import librosa
import librosa.display
import pylab
import numpy as np


x, sr = librosa.load('audio/example.wav')
mel = librosa.feature.melspectrogram(x,sr)
P = librosa.power_to_db(mel, ref=np.max)
librosa.display.specshow(P)
pylab.savefig("example.png", bbox_inches=None, pad_inches=0)

据我了解,频谱图只是音频信号 STFT 矩阵的直观表示。 我正在尝试重建用于生成频谱图的 STFT 矩阵,以便通过 griffin lim function 传递它。我应该怎么做?

使用 STFT 数据生成频谱图

def generate_spectrogram(x, sr):
    X = librosa.stft(x)
    Xdb = librosa.amplitude_to_db(abs(X))
    fig = plt.figure(figsize=(10, 10), dpi=100, frameon=False)
    ax = fig.add_axes([0, 0, 1, 1], frameon=False)
    ax.axis('off')
    librosa.display.specshow(Xdb, sr=sr, cmap='gray', x_axis='time', y_axis='hz')
    plt.savefig('example.png', quality=100, bbox_inches=0, pad_inches=0)
    librosa.cache.clear()

我不确定这个问题是否适合这个论坛的当前形式(堆栈交换可能更合适),但由于它与基于 DNN 的语音合成管道非常相关,我认为扩展它有点。

我们无法从 Mel 频谱图中准确重建 STFT。 原因是我们 Mel 是 STFT 的“压缩”版本,频率来自 Mel 标度,然后在这些频率上应用(到 STFT)三角滤波器。 通常,我们会丢失从 STFT 到 mel 的信息。 有关详细说明,请参阅这篇优秀文章。

https://haythamfayek.com/2016/04/21/speech-processing-for-machine-learning.html

现在,回到您的问题 - 我假设您正在以 Tacotron [1] 工作的方式进行语音合成 - 为了应用 Griffin Lim,正如您正确指出的那样,我们需要线性频谱图。 论文中的做法是使用神经网络将 Mel 转换为 STFT。 他们称其为 pos.net,因为它在预测 Mels 之后用作后处理器。

要设置 this.network,将 ground truth(目标)音频转换为 Mels,并创建一个 recurrent.network(CBHG 或其他)以将其转换为 STFT 等价物。 最小化这些 STFT 预测与我们可以从目标音频创建的实际 STFT 之间的损失。

[1] https://arxiv.org/abs/1703.10135

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM