我正在使用
import matplotlib.pyplot as plt
from scipy.io import wavfile
import numpy as np
def graph_spectrogram(wav_file,png_file):
rate, data = wavfile.read(wav_file)
fig,ax = plt.subplots(1)
fig.subplots_adjust(left=0,right=1,bottom=0,top=1)
ax.axis('off')
pxx, freqs, bins, im = ax.specgram(x=data, Fs=rate, noverlap=384, NFFT=512)
ax.axis('off')
fig.savefig(png_file, dpi=300, frameon='false')
if __name__ == '__main__': # Main function
graph_spectrogram(file)
将波形文件转换为fft图像。无论音频文件的长度如何,所有输出文件均为1920 x 1440。如何保持高度,但输出图像的宽度取决于音频文件的长度?