【问题标题】:.wav file error : "AttributeError: 'bytes' object has no attribute 'seek'" in python.wav 文件错误:python 中的“AttributeError:‘bytes’对象没有属性‘seek’”
【发布时间】:2020-12-12 22:01:58
【问题描述】:

我正在尝试循环播放大量音频文件,并希望将它们分成 5 秒的片段。

问题的相关代码如下。

for file in os.listdir(directory):
    
    f = sf.SoundFile(file)
    
    audio_file = AudioSegment.from_file(file, "wav")

我收到一个错误:“AttributeError: 'bytes' 对象没有属性 'seek'”

我很欣赏该文件是字节格式,但我尝试将其转换为字符串等,但没有成功,因为这样做时出现权限被拒绝错误。

【问题讨论】:

    标签: python audio soundfile


    【解决方案1】:

    如果你使用的是pydub,可以使用AudioSegment.from_wav(file)或AudioSegment.from_raw(file, sample_width, frame_rate)

    【讨论】:

    • conda install -c conda-forge ffmpeg 是我缺少的一个库,在我安装之前,上述内容对我不起作用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-24
    • 2021-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-13
    • 2023-03-22
    相关资源
    最近更新 更多