【发布时间】:2018-03-29 05:44:52
【问题描述】:
我该怎么做:
- 阅读我的音频文件
- 存储在二进制文件中,
谁能给我例子来在python中实现编码器和解码器?
【问题讨论】:
-
“二进制文件”是什么意思?这样的文件长什么样子?
-
带有 ***.bin 的文件
标签: python audio encoder decoder
我该怎么做:
谁能给我例子来在python中实现编码器和解码器?
【问题讨论】:
标签: python audio encoder decoder
您可以使用 scipy.wave 来读取和写入 wav 文件。要存储数据,您可以使用 numpy。
如果音频文件被有效编码为每个样本 16 位,则您无需执行任何操作,这应该类似于:
from scipy.io.wavfile import read as wavread
from scipy.io.wavfile import write as wavwrite
import numpy as np
sr, sig = wavread(audioFileName) #read the audio file (samplig rate, signal)
sig_int8 = np.uint8(sig) # cast the data in uint8
np.savez(out_file, sig = sig_int8) # store the data
npzfile = np.load(out_file + '.npz') #load the data
sig = npzfile['sig']
wavwrite(audioFileName2, sr, sig) #write data in wav file
【讨论】: