我发现读取带有soundfile
和wavefile
的wav文件之间的幅度响应存在问题。以下是不同的图:
你能告诉我需要在wavefile.read
中调整什么以获得与soundfile.read
相同的大小吗
以下是我使用的代码:
import os
import matplotlib.pyplot as plt
from matplotlib import transforms
import numpy as np
import soundfile as sf
import scipy.io.wavfile as wavfile
from matplotlib.gridspec import GridSpec
input_file1 = (r'G:/file.wav')
plt.subplot(211)
a, b = sf.read(input_file1);
pxx, fs = plt.psd(a, 512, b)
plt.semilogx(fs, 10*np.log10(pxx))
plt.title('Sound File Read')
plt.grid(which='major', axis='both', color='g', linestyle='-', alpha=0.4)
plt.grid(which='minor', axis='x', color='g', linestyle='-', alpha=0.1)
plt.subplot(212)
sample_rate, signal1 = wavfile.read(input_file1)
Pxx, freq = plt.psd(signal1, 512, sample_rate)
plt.semilogx(freq, 10*np.log10(Pxx))
plt.grid(which='major', axis='both', color='g', linestyle='-', alpha=0.4)
plt.grid(which='minor', axis='x', color='g', linestyle='-', alpha=0.1)
plt.title('Wavfile File Read')
plt.ylabel('PSD')
plt.xlabel('Frequency (Hz)')
# set the spacing between subplots
plt.tight_layout()
plt.show()
Here is a link to an example .wav file.
谢谢
根据您报告的两个值,它确实看起来像
soundfile.read
给了您一个介于-1和1之间的float64
数组,而wavfile.io.read
给了您一个介于-2147483648和2147483647之间的int32
数组(-4850432/2147483648=-0.00225866)。您可以使用以下命令从int_
或float_
数组创建规范化的float_
数组:相关问题 更多 >
编程相关推荐