将wav文件转换为频谱图python

时间:2019-11-18 18:34:03

标签: python image-processing wav spectrogram

我正在尝试将wav文件转换为特定外观的频谱图,但遇到了一些问题。我正在使用的文件是一首名为Reflections的歌曲。您可以访问here并选择“下载相册”,以$ 0的价格输入价格,然后将其作为WAV文件下载,以访问wav文件。

import os
import numpy as np
import matplotlib.pyplot as plt
import obspy
from obspy.signal.tf_misfit import cwt
import pylab
from pydub import AudioSegment


file = 'Matt Wolfe - If Kids were Kings - 06 Reflections.wav'
sound = AudioSegment.from_wav(file)
print('Converting', file, 'to single Channel')

sound = sound.set_channels(1)
sound.export('sc_'+file, format="wav")
file = 'sc_'+file

# create spectogram
print('Reading Wav file and creating Spectrogram...')
samplerate, test_sound  = wavfile.read(file)
_, spectrogram = log_specgram(test_sound, samplerate)

plt.imshow(spectrogram.T, interpolation='bilinear',  aspect='auto', origin='lower')
plt.axis('off')
plt.show()

print('Saving Image of Spectrogram...')
plt.savefig(file.replace('.wav', '.jpg'))

Spectrogram of Song

我正在尝试将声音转换成更多的图像,如图here所示。而不是上面发布的那个。

0 个答案:

没有答案