首页 > 解决方案 > tf.signal.stft 返回 -inf

问题描述

我正在关注有关音频识别的本教程 [https://www.tensorflow.org/tutorials/audio/simple_audio][1]

当我使用函数 tf.signal.stft 时,结果是一个包含多个元素且具有 -inf 值的数组。我认为这是因为波形包含一些 0,此问题仅在将某些音频文件转换为 wav(mp3、mp4、m4a)时出现,但在 ogg 中不会出现。我真的不知道该怎么办:(。

def get_stft(audio, frame_length=2048, frame_step=512, fft_length=256):
    return tf.signal.stft(
        tf.cast(audio, tf.float32),
        frame_length=frame_length,
        frame_step=frame_step,
        fft_length=fft_length
    )
def get_spectrogram(audio):
    audio_stft = get_stft(audio)
    audio_spec = tf.abs(audio_stft)
    return tf.math.log(tf.transpose(audio_spec))

def get_waveform(filename):
    raw_audio = tf.io.read_file(filename)
    waveform, _ = tf.audio.decode_wav(raw_audio,desired_channels=1)
    waveform=tf.squeeze(waveform, axis=-1)
    return waveform

标签: pythontensorflowaudiosignal-processing

解决方案


推荐阅读