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 loadMNISTImages(filename): f = open(filename, 'rb') # Verify Magic Number s = f.read(4) magic = int(s.encode('hex'),16) assert(magic == 2051) # Get Number of Images s = f.read(4) numImages = int(s.encode('hex'),16) s = f.read(4) numRows = int(s.encode('hex'),16) s = f.read(4) numCols = int(s.encode('hex'),16) # Get Data s = f.read() a = frombuffer(s, uint8) # Use 'F' to ensure that we read by column a = reshape(a, (numCols , numRows, numImages), order='F'); images = transpose(a, (1, 0, 2)) f.close() # Reshape to #pixels * #examples images = reshape(a, (shape(images)[0] * shape(images)[1], numImages), order='F'); images = double(images)/255 return images
def __init__(self, audioName): self.wf = wave.open(audioName, "r") buffer = self.wf.readframes(self.wf.getnframes()) self.data = plt.frombuffer(buffer, dtype="int16") self.Y = None self.freqs = None self.bins = None print ("MyWav_init")
def __init__(self, audioName): self.wf = wave.open(audioName, "r") buffer = self.wf.readframes(self.wf.getnframes()) self.data = plt.frombuffer(buffer, dtype="int16") self.Y = None self.freqs = None self.bins = None print("MyWav_init")
def get_raw_specgram_for_frame(self, frame, pad_seconds=DEFAULT_PADDING): if pad_seconds: pad_frames = int(self.audio_params.framerate * pad_seconds) (nchannels, sampwidth, framerate, nframes, comptype, compname) = self.audio_params raw_data = self.extract_specgram_data_for_frame(frame=frame, pad_frames=pad_frames) data = pylab.frombuffer(raw_data, 'Int' + str(8 * self.audio_params.sampwidth)) min_frame = max(0, frame - pad_frames) max_frame = min(frame + pad_frames, nframes) audio_pos = frame * 1.0 / framerate audio_min = max(0, audio_pos - pad_seconds) audio_max = min(audio_pos + pad_seconds, nframes * 1.0 / framerate) pylab.figure(num=None, figsize=(8, 6)) pylab.subplot(111) pylab.title('Spectrogram of {0}: {1:04.5f} - {2:04.5f} s'.format(self.filename, audio_min, audio_max)) pylab.suptitle('Frames {0:09d} - {1:09d}'.format(min_frame, max_frame)) # results = pyfigaxes.specgram(data, Fs=self.audio_params.framerate) return pylab.specgram(data, Fs=framerate, NFFT=1024, noverlap=512)
def loadMNISTLabels(filename): f = open(filename, 'rb') # Verify Magic Number s = f.read(4) magic = int(s.encode('hex'), 16) assert(magic == 2049) # Read Number Labels s = f.read(4) numLabels = int(s.encode('hex'), 16) # Get Data s = f.read() f.close() labels = frombuffer(s, uint8) assert(len(labels) == numLabels) return labels