import wave
r = r"D:\沫沫醬 - 舊傷口.wav" # 一個.wav格式文件
with wave.open(r, "rb") as f:
# 讀取文件格式等
params = f.getparams()
nchannels, sampwidth, framerate, nframes = params[:4] # 聲道數,樣本寬度,採樣率,幀數
data = f.readframes(nframes) # 讀取音頻數據
# print(data)
print(nframes)
with wave.open("隨便一個名字.wav", "wb") as f:
# 對文件寫入如下格式數據
f.setnchannels(nchannels) # 聲道數
f.setsampwidth(sampwidth) # 樣本寬度
f.setframerate(framerate) # 採樣率
f.setnframes(framerate) # 幀數
# 寫入音頻數據
f.writeframesra
w(data) # 寫入音頻數據
# 更多請查看:https://docs.python.org/2/library/wave.html#