转换波24位到16位bi

2024-10-01 02:26:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想转换一些wav 48kHz 24位文件.wav至48kHz 16位文件-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]

谢谢


Tags: 文件sampleimportnpopenwavedawav
1条回答
网友
1楼 · 发布于 2024-10-01 02:26:39

如果您只想将文件从24位转换为16位,那么您可以使用SoX,这不会比这简单得多:

sox file.wav -b 16 file-2.wav

SoX还可以做更多的事情,只需看看它的man page。在

如果您想使用Python,我建议使用soundfile模块:

^{pr2}$

指定subtype='PCM_16'甚至不是绝对必要的,因为它是默认值。在

如果您真的想用内置的ẁave模块来做,请看一下我的tutorial about the ^{} module。在

相关问题 更多 >