python 提取wav文件的时域特征代码
时间: 2023-06-04 18:03:59 浏览: 163
以下是Python语言提取WAV文件时域特征的代码:
```python
import matplotlib.pyplot as plt
import numpy as np
import wave
import sys
# 打开WAV文件
wave_file = wave.open("audio.wav", "rb")
# 读取参数
sample_rate = wave_file.getframerate()
num_channels = wave_file.getnchannels()
sample_width = wave_file.getsampwidth()
num_frames = wave_file.getnframes()
# 读取数据
data = wave_file.readframes(num_frames)
# 将数据转换成数字
if sample_width == 1:
data = np.fromstring(data, dtype=np.uint8)
elif sample_width == 2:
data = np.fromstring(data, dtype=np.int16)
else:
raise ValueError("Unsupported sample width")
#
阅读全文