用python编写一段常见音频格式转为wav格式的代码
时间: 2023-03-14 08:21:58 浏览: 130
我可以用下面这段代码来实现:import wave
import contextlibwith contextlib.closing(wave.open('input.mp3','r')) as f:
frames = f.getnframes()
rate = f.getframerate()
duration = frames / float(rate)
with wave.open('output.wav', 'w') as f2:
f2.setnchannels(1)
f2.setsampwidth(2)
f2.setframerate(rate)
f2.setnframes(frames)
f2.writeframes(f.readframes(frames))
阅读全文