wav转为npy,其中npy包含行数列数通道数
时间: 2024-05-15 13:14:05 浏览: 257
你可以使用Python中的NumPy库将WAV文件转换为Numpy数组,然后将该数组保存为Numpy二进制文件(.npy)。
以下是一个示例代码,可以将WAV文件加载为Numpy数组,并将其保存为包含行数、列数和通道数的Numpy文件:
```python
import numpy as np
import scipy.io.wavfile as wav
# Load the WAV file
sample_rate, audio_data = wav.read('audio_file.wav')
# Convert the audio data to a Numpy array
audio_data = np.array(audio_data)
# Get the shape of the audio data array
num_samples, num_channels = audio_data.shape
# Save the audio data array as a Numpy binary file (npy)
np.save('audio_file.npy', audio_data)
# Load the Numpy binary file (npy) back into a Numpy array
loaded_audio_data = np.load('audio_file.npy')
# Get the shape of the loaded audio data array
num_samples, num_channels = loaded_audio_data.shape
```
注意,这个代码假设WAV文件是单声道或立体声道。如果你的WAV文件有更多的声道,请相应地修改代码。
阅读全文