我想转换一些wavs 48kHz 24 位 file.wav 至 48kHz 16 位 file-2.wav
import wave
origAudio = wave.open("Sample_5073.wav","r")
frameRate = origAudio.getframerate()
nChannels = origAudio.getnchannels()
sampWidth = origAudio.getsampwidth()
nbframe=origAudio.getnframes()
da = np.fromstring(origAudio.readframes(48000), dtype=np.int16)
left, right = da[0::2], da[1::2]
谢谢
最佳答案
如果您只想将文件从 24 位转换为 16 位,则可以使用 SoX ,没有比这更容易的了:
sox file.wav -b 16 file-2.wav
SoX 还可以做更多的事情,看看它的 man page 就可以了。 .
如果你想使用Python,我推荐soundfile模块:
import soundfile as sf
data, samplerate = sf.read('file.wav')
sf.write('file-2.wav', data, samplerate, subtype='PCM_16')
指定 subtype='PCM_16'
甚至不是严格必要的,因为它无论如何都是默认值。
如果您确实想使用内置的 ẁave
模块来完成此操作,请查看我的 tutorial about the wave
module .
关于python - 转换器 wav 24 位到 16 位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39788464/