python 从多声道 pcm 文件中 转换成单通道 pcm 文件


1. 从 二进制 pcm 文件中读取数据,并转化位想要的矩阵数组

    with open(audioPath, 'rb') as f:
        audioData = np.fromfile(f, dtype = np.uint16)
    audioData.shape = -1, 8

转换的音频数据是 不确定行,8列数组。

2. 把矩阵转置,以单声道数据为行。

    audioData = audioData.T

转换为 8行的二维数组,每一行就是一个声道的数据。

3. 抽取一个通道的数据。

    ch1 = audioData[4]

4. 把这个通道的数据写入二进制文件

    ch1.tofile("./audio/ch1.pcm")

参考: https://blog.51cto.com/feature09/2316652
https://blog.csdn.net/Tourior/article/details/110791039
https://blog.csdn.net/kebu12345678/article/details/54837245
https://numpy.org/doc/stable/reference/generated/numpy.fromfile.html#:~:text=numpy.fromfile. ¶. numpy.fromfile(file%2C dtype%3Dfloat%2C count%3D-1%2C sep%3D''%2C offset%3D0) ¶.,tofile method can be read using this function.
https://www.cnblogs.com/peixu/p/7991715.html
https://blog.csdn.net/botao_li/article/details/104378469
https://www.cnblogs.com/noluye/p/11224137.html


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM