读取音频信息使用python代码
时间: 2023-01-28 14:15:04 浏览: 131
如果你想使用 Python 来读取音频信息,可以使用一些第三方库,比如 scipy、wave 或者 PySoundFile。
下面是使用 scipy 读取 WAV 文件的示例代码:
```python
import scipy.io.wavefile
# 读取 WAV 文件
wave_data, sample_rate = scipy.io.wavefile.read('audio.wav')
# 输出采样率和音频数据
print(sample_rate)
print(wave_data)
```
如果你想使用 wave 库来读取音频文件,可以使用下面的代码:
```python
import wave
# 打开 WAV 文件
with wave.open('audio.wav', 'rb') as wav_file:
# 读取音频信息
sample_rate = wav_file.getframerate()
num_channels = wav_file.getnchannels()
sample_width = wav_file.getsampwidth()
num_frames = wav_file.getnframes()
# 读取音频数据
wave_data = wav_file.readframes(num_frames)
# 输出采样率和音频数据
print(sample_rate)
print(wave_data)
```
如果你想使用 PySoundFile 库来读取音频文件,可以使用下面的代码:
```python
import soundfile
# 读取音频文件
wave_data, sample_rate = soundfile.read('audio.wav')
# 输出采样率和音频数据
print(sample_rate)
print(wave_data)
```
这些库都可以用来读取常见的音频格式,比如 WAV、MP3 和 AIFF。
阅读全文
相关推荐


















