简体   繁体   English

如何将 numpy 数组中的 32 位 wav 文件转换为 24 位 wav 文件?

[英]How to convert 32bit wav file in a numpy array to a 24bit wav file?

I would like to convert a 32-bit wav numpy array to a 24-bit wav numpy array using python3 and the numpy library.我想使用 python3 和 numpy 库将 32 位 wav numpy 数组转换为 24 位 wav numpy 数组。

I am reading the file like this:我正在阅读这样的文件:

import numpy as np
    sample_rate, file_info = read(filepath)
    np_array = np.array(file_info)

Now based on the dtype which can be extracted via something like this现在基于可以通过这样的东西提取的dtype

if (str(np_array.dtype) == 'int32'):

I would like to retranscode the np_array to become a 24bit array.我想将 np_array 重新转码为 24 位数组。 I need to do this for analysis purposes.我需要这样做以进行分析。 The goal is - not to generate a new file.目标是 - 不生成新文件。

Any hints in how to do this effectively?关于如何有效地做到这一点的任何提示?

Thank you谢谢

import sox

 

transformer = sox.Transformer()
transformer.convert(samplerate=sample_rate, bitdepth=16)
sox_array = transformer.build_array(sample_rate_in=sample_rate, input_array=np_array)

This will convert the array to 16bit, which allows for analysis workflows, which will always be the same.这会将数组转换为 16 位,从而允许分析工作流程,这将始终相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM