SoX:.wav 输入文件上的 EOF 过早

SoX: Premature EOF on .wav input file

我有一堆 WAV 文件和一个将它们复制到另一个目录的脚本,但使用 SoX 处理了一些文件。输出的文件都应该有 1 个通道,采样率不超过 44.1khz。我的大多数文件要么有一个以上的通道,要么采样率大于 44.1khz,但只有 3 个文件同时具有这两种通道。使用下面的代码片段转换这 3 个文件时,出现“sox WARN wav:.wav 输入文件上的 EOF 过早”错误。

# $x is the filename + extension
#  is the destination folder
convertedWAV=false
hz=$(sox --info $PWD/$x | sed -n 4p | tr ' ' '\n' | tail -1)
chan=$(sox --info $PWD/$x | sed -n 3p | tr ' ' '\n' | tail -1)

# If its more than 44.1khz, then bring it down to that
if [[ $hz > 44100 ]]; then
    echo "ADJUSTING HZ"
    convertedWAV=true
    sox $PWD/$x --rate 44100 /$x
fi

# If its more than 1 channel (AKA Stereo), then reduce it.
if [[ $chan > 1 ]]; then
    echo "ADJUSTING CHANNELS"
    if [[  $convertedWAV == false ]]; then
        sox $PWD/$x --channels 1 /$x
    else
        sox /$x --channels 1 /$x
    fi
    convertedWAV=true
fi

if [[ $convertedWAV == false ]]; then
    ln "$PWD/$x" ""
fi

注意这 3 个文件是如何通过两个单独的 SoX 命令的。然后我修改了我的脚本,如果两个通道 > 1 和 hz > 44100 则它执行单个 sox 命令,代码如下所示。

if [[ $chan > 1 ]] && [[ $hz > 44100 ]]; then
    sox $PWD/$x --channels 1 --rate 44100 /$x
elif [[ $chan > 1 ]]; then
    sox $PWD/$x --channels 1 /$x
elif [[ $hz > 44100 ]]; then
    sox $PWD/$x --rate 44100 /$x
else
    cp "$PWD/$x" "/$x"
fi

现在可以了。我的问题是,为什么? 如果我执行 sox $PWD/$x --rate 44100 --channels 1 /$x,它的行为相同,出于某种原因,在两个命令中执行它会导致问题。我找不到明确的答案。根据 this the error can happen because the hdr's length isn't actually the length, so maybe the first SoX command corrupts the file slightly? I don't know if this is a bug with SoX's conversions or something wrong with my audio file/s. I've uploaded one of them here incase 这有帮助。

sox /$x --channels 1 /$x

您不能将文件 $2/$x 连接到自身。