ramlife

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

posted on 2020-12-11 18:24  ramlife  阅读(1028)  评论(0编辑  收藏  举报