primera_parte/main.py (816B)
1 import matplotlib.pyplot as plt 2 3 from numpy import arange 4 from scipy.io import wavfile 5 6 file_names = ['InASentimentalMood.wav', 'Zombie.wav'] 7 8 def plot_wav_data(time, data, file_name): 9 figure_title = 'Gráfico de `' + str(file_name) + '` en dominio de tiempo' 10 11 new_figure = plt.figure(num=figure_title, figsize=(12, 6)) 12 plt.plot(time, data, label='Señal de Audio') 13 plt.title(figure_title) 14 plt.xlabel('Tiempo [s]') 15 plt.ylabel('Amplitud') 16 plt.grid(True) 17 plt.legend() 18 19 return new_figure 20 21 figures = [] 22 for i, file_name in enumerate(file_names): 23 sample_rate, data = wavfile.read(file_name) 24 25 if len(data.shape) > 1: 26 data = data[:, 0] 27 28 time = arange(len(data)) / sample_rate 29 figures.append(plot_wav_data(time, data, file_name)) 30 figures[i].show() 31 32 plt.show()