【问题标题】:"Bad audio format for WAV" when reading a wav file读取 wav 文件时出现“WAV 音频格式错误”
【发布时间】:2021-07-22 15:21:17
【问题描述】:

我有一组想要生成频谱图的 wav 文件。但是当我使用 tf.audio.decode_wav 函数时,我得到以下错误:

InvalidArgumentError:WAV 的音频格式错误:预期为 1 (PCM),但 got7 [Op:DecodeWav]

如何规避此错误?还有其他方法可以使用 tensorflow 为 wav 文件生成 log mel 频谱图吗?

我知道 librosa 包,但我更喜欢 tensorflow。

代码是:

def decode_audio(audio_binary):
  audio, _ = tf.audio.decode_wav(audio_binary)
  return tf.squeeze(audio, axis=-1)

def get_waveform_and_label(file_path):
  audio_binary = tf.io.read_file(file_path)
  waveform = decode_audio(audio_binary)
  return waveform

【问题讨论】:

标签: tensorflow wav librosa audio-processing


【解决方案1】:

该错误告诉您,您的文件表明它们具有编码为 8 位 mulaw 的样本。

tf.audio.decode_wav 的 TensorFlow 文档中所述,此方法仅支持 16 位 PCM WAV。

在将波形文件传递给 tensorflow 之前,您需要重新编码它们。像 ffmpeg 这样的东西可以在这里提供帮助。

【讨论】:

    猜你喜欢
    • 2021-10-03
    • 2018-04-08
    • 1970-01-01
    • 2020-06-07
    • 2014-09-19
    • 1970-01-01
    • 2020-04-24
    • 2021-04-06
    • 1970-01-01
    相关资源
    最近更新 更多