我正在尝试使用wave模块编辑wav文件的长度。然而,似乎我无法到达任何地方,因为我一直得到相同的错误,没有指定通道数。不过,当我写一些东西看到频道的数量时,我仍然会收到该错误,或者当我尝试设置频道数时,如下所示:
def editLength(wavFile):
file = wave.open(wavFile, 'w')
file.setnchannels(file.getnchannels())
x = file.getnchannels()
print (x)
答案 0 :(得分:0)
来自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()
时未指定通道数。
def editLength(wavFile):
with open(wavFile, "rb") as file:
x = file.getnchannels()
print(x)
如果要编辑文件,应首先从原始文件读取并写入临时文件。然后将临时文件复制到原始文件上。