转换器 wav 24 位到 16 位
converter wave 24 bit to 16 bit
我想转换一些wavs
48kHz 24 位 file.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]
谢谢
如果将文件从 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。
我想转换一些wavs 48kHz 24 位 file.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]
谢谢
如果将文件从 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。