gpt4 book ai didi

python - wave.error : # channels not specified 错误

转载 作者:太空狗 更新时间:2023-10-30 01:36:31 25 4
gpt4 key购买 nike

我正在尝试使用 wave 模块编辑 wav 文件的长度。但是,似乎我无法到达任何地方,因为我不断收到未指定 channel 数的相同错误。尽管如此,当我写一些东西来查看 channel 数时,我仍然会遇到该错误,或​​者当我尝试设置 channel 数时,如下所示:

def editLength(wavFile):
file = wave.open(wavFile, 'w')
file.setnchannels(file.getnchannels())
x = file.getnchannels()
print (x)

最佳答案

来自 https://docs.python.org/3.7/library/wave.html#wave.open

wave.open(file, mode=None)

If file is a string, open the file by that name, otherwise treat it as a file-like
object.

mode can be:
'rb' Read only mode.
'wb' Write only mode.

Note that it does not allow read/write WAV files.

您尝试从 WAV 文件读取和写入,文件对象在第一个 file.getnchannels() 时没有指定 channel 数。

def editLength(wavFile):
with open(wavFile, "rb") as file:
x = file.getnchannels()
print(x)

如果你想编辑文件你应该先从原始文件中读取并写入一个临时文件。然后将临时文件复制到原始文件上。

关于python - wave.error : # channels not specified 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47732657/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com