【问题标题】:Encodeer and decoder in python/ from wav to bin [closed]python /从wav到bin中的编码器和解码器[关闭]
【发布时间】:2018-03-29 05:44:52
【问题描述】:

我该怎么做:

  • 阅读我的音频文件
  • 存储在二进制文件中,

谁能给我例子来在python中实现编码器和解码器?

【问题讨论】:

  • “二进制文件”是什么意思?这样的文件长什么样子?
  • 带有 ***.bin 的文件

标签: python audio encoder decoder


【解决方案1】:

您可以使用 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

【讨论】:

  • 如果我需要将声音文件中的音频样本量化为每个样本 8 位,我应该在您的程序中进行哪些更改?
  • 在 scipy write 中,有一个速率选项。见这里:docs.scipy.org/doc/scipy-0.18.1/reference/generated/…
  • 我写了 smt 像:wavwrite(file name, sr,'uint8') anf got the error: 'str' object has no attribute 'dtype'。
  • 我编辑了答案
猜你喜欢
  • 1970-01-01
  • 2023-04-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多