Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- def get_wav_info(wav_file):
- wav = wave.open(wav_file, 'r')
- frames = wav.readframes(-1)
- sound_info = pylab.frombuffer(frames, 'int16')
- frame_rate = wav.getframerate()
- wav.close()
- return sound_info, frame_rate
- def get_audio_info(file):
- wav = AudioSegment.from_file(file)
- frames = wav.get_array_of_samples()
- sound_info = pylab.frombuffer(frames.tobytes())
- frame_rate = wav.frame_rate
- return sound_info, frame_rate
- def graph_spectrogram(wav_file):
- if wav_file[-3:] == 'wav':
- sound_info, frame_rate = get_wav_info(wav_file)
- elif wav_file[-3:] == 'm4a':
- sound_info, frame_rate = get_audio_info(wav_file)
- print(type(sound_info))
- print(sound_info.shape)
- sound_info = sound_info[460000:920000]
- pylab.figure(num=None, figsize=(19, 12))
- pylab.subplot(111)
- pylab.title('spectrogram of %r' % wav_file)
- pylab.specgram(sound_info, Fs=frame_rate)
- # pylab.savefig('spectrogram.png')
- pylab.show()
- if __name__ == '__main__':
- graph_spectrogram('rec_andrey.wav')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement