Hello,
I am executing the following program for SE32_LE wave file format:
Channels = 2
Sample width = 4
Frame rate = 8000
Frames = 23493
Audio data = [ 0 0 0 ... 0 0 -6]
Hello Buran,
I shall take care henceforth
Than you
I am executing the following program for SE32_LE wave file format:
import wave import matplotlib.pyplot as plt import numpy as np f = wave.open("M1F132.wav", "rb") #rb = read only # (nchannels, sampwidth, framerate, nframes, comptype, compname) params = f.getparams() nchannels, sampwidth, framerate, nframes = params[:4] print("Channels =", nchannels) print("Sample width =", sampwidth) print("Frame rate =", framerate) print("Frames =", nframes) str_data = f.readframes(nframes) #Reads and returns at most n frames of audio, as a bytes object. f.close() #length = f.getnframes() #for i in range(0,length): # waveData = f.readframes(1) # data = struct.unpack("<h", waveData) # print(int(data[0])) wave_data = np.fromstring(str_data, dtype=np.short) #A new 1-D array initialized from text data in a string # str_data is string containing the data #dtype= The data type of the array; default: float print ("Audio data =", wave_data) wave_data.shape = -1, 2 #formats array in rows and columns #-1. In this case, the value is taken from the length of the array and remaining dimensions. wave_data = wave_data.T #.T is self transpose the array i.e. rows to columns time = np.arange(0, nframes) * (1.0 / framerate) #for creating time axis for plot, arrange for no. of frames, (1.0 / framerate) will create in seconds #arange = Returns evenly spaced values within a given interval. figure = plt.gcf() # get current figure figure.set_size_inches(8*20, 6) duration = nframes/float(framerate) xticks = np.arange(0, duration, 2) plt.subplot(211).set_xticks(xticks) plt.plot(time, wave_data[0]) plt.title('Audio channel 1', loc='left') plt.subplot(212).set_xticks(xticks) plt.plot(time, wave_data[1], c="g") plt.xlabel("time (seconds)") plt.title('Audio channel 2', loc='left') plt.savefig('Audio.png', dpi=100, bbox_inches='tight', pad_inches=0.1) plt.show() #plt.close(figure)but i am getting the following error:
Channels = 2
Sample width = 4
Frame rate = 8000
Frames = 23493
Audio data = [ 0 0 0 ... 0 0 -6]
Error:Traceback (most recent call last):
File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\trywav.py", line 45, in <module>
plt.plot(time, wave_data[0])
File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\pyplot.py", line 2813, in plot
is not None else {}), **kwargs)
File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\__init__.py", line 1810, in inner
return func(ax, *args, **kwargs)
File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_axes.py", line 1611, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_base.py", line 393, in _grab_next_args
yield from self._plot_args(this, kwargs)
File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_base.py", line 370, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Users\a\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_base.py", line 231, in _xy_from_xy
"have shapes {} and {}".format(x.shape, y.shape))
ValueError: x and y must have same first dimension, but have shapes (23493,) and (46986,)
PLease guideHello Buran,
I shall take care henceforth
Than you