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#
原文地址:https://www.cnblogs.com/guihua-pingting/p/12207613.html
时间: 2024-10-17 21:31:23