【问题标题】:ValueError: Input signal length=2 is too small to resample from 44100->16000ValueError: Input signal length=2 is too small to resample from 44100->16000
【发布时间】:2021-06-25 11:11:35
【问题描述】:

我正在尝试读取一些音频 wav 文件,但在我添加更多音频文件之前,一切都很完美,但我遇到了错误。使用以下代码读取音频文件并将其重新采样到 16KHz

def speech_file_to_array_fn(batch):
    start = 0 
    stop = 20 
    srate = 16_000
    speech_array, sampling_rate = sf.read(batch["file"], start = start * srate , stop = stop * srate)
    batch["speech"] = librosa.resample(np.asarray(speech_array), sampling_rate, srate)
    batch["sampling_rate"] = srate
    batch["parent"] = batch["label"]
    return batch

我收到此错误:

ValueError: Input signal length=2 is too small to resample from 44100->16000

我在阅读后尝试转置音频文件,但没有成功

谢谢

【问题讨论】:

  • python 不是我的语言,但srate = 16_000 似乎很奇怪......下划线在那里做什么?
  • 我删除了它仍然面临同样的错误
  • 数字中的下划线在python中很好,即16_000 == 16000 >>> True

标签: python python-3.x audio sampling librosa


【解决方案1】:

我相信这已在this issue 的 GitHub 上为librosa 讨论过。

我以前从未使用过该库,但从 this comment 看来,在您的情况下,您可以执行以下操作:

def speech_file_to_array_fn(batch):
    start = 0 
    stop = 20 
    srate = 16_000
    speech_array, sampling_rate = sf.read(batch["file"], start = start * srate , stop = stop * srate)
    speech_array = speech_array.T
    batch["speech"] = librosa.resample(np.asarray(speech_array), sampling_rate, srate)
    batch["sampling_rate"] = srate
    batch["parent"] = batch["label"]
    return batch

让我知道这是否有效,因为我无法测试它。

【讨论】:

    猜你喜欢
    • 2019-02-01
    • 2019-01-19
    • 2020-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-09-11
    • 2020-04-01
    相关资源
    最近更新 更多