python 從多聲道 pcm 檔案中 轉換成單通道 pcm 檔案
阿新 • • 發佈:2020-12-11
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