(self)
Read RIFF WAV header.
Read RIFF WAV header.
Read RIFF WAV header .
def _read_wav_header(self):
        """Read RIFF WAV header."""
        try:
            ch = Chunk(self.wav, bigendian=0)
        except (EOFError):
            logging.debug('WAV file is corrupted.')
            return False
        if ch.getname() != b'RIFF' or ch.read(4) != b'WAVE':
            logging.debug('Not a WAV file.')
            return False
        # this would normally be 0
        self.riff_pos = self.wav.tell() - 12
        riff_size = ch.getsize()
        self.sampwidth, self.nchannels, self.framerate = 0, 0, 0
        while True:
            try:
                chunk = Chunk(ch, bigendian=0)
            except EOFError:
                logging.debug('No data chunk found in WAV file.')
                return False
            chunkname = chunk.getname()
            if chunkname == b'fmt ':
                format_tag, self.nchannels, self.framerate, _, _ = struct.unpack(
                    '<HHLLH', chunk.read(14)
                )
                if format_tag == 1:
                    sampwidth = struct.unpack('<H', chunk.read(2))[0]
                    self.sampwidth = (sampwidth + 7) // 8
                else:
                    logging.debug('WAV file not in uncompressed PCM format.')
                    return False
            elif chunkname == b'data':
                if not self.sampwidth:
                    logging.debug('Format chunk not found.')
                    return False
                self.data_pos = self.wav.tell() - 4
                #self.wav.read(4)
                self.start = self.wav.tell()
                return True
            chunk.skip()
def _read_wav_header ( self ) : try : ch = Chunk ( self . wav , bigendian = 0 ) except ( EOFError ) : logging . debug ( 'WAV file is corrupted.' ) return False if ch . getname ( ) != b'RIFF' or ch . read ( 4 ) != b'WAVE' : logging . debug ( 'Not a WAV file.' ) return False # this would normally be 0 self . riff_pos = self . wav . tell ( ) - 12 riff_size = ch . getsize ( ) self . sampwidth , self . nchannels , self . framerate = 0 , 0 , 0 while True : try : chunk = Chunk ( ch , bigendian = 0 ) except EOFError : logging . debug ( 'No data chunk found in WAV file.' ) return False chunkname = chunk . getname ( ) if chunkname == b'fmt ' : format_tag , self . nchannels , self . framerate , _ , _ = struct . unpack ( '<HHLLH' , chunk . read ( 14 ) ) if format_tag == 1 : sampwidth = struct . unpack ( '<H' , chunk . read ( 2 ) ) [ 0 ] self . sampwidth = ( sampwidth + 7 ) // 8 else : logging . debug ( 'WAV file not in uncompressed PCM format.' ) return False elif chunkname == b'data' : if not self . sampwidth : logging . debug ( 'Format chunk not found.' ) return False self . data_pos = self . wav . tell ( ) - 4 #self.wav.read(4) self . start = self . wav . tell ( ) return True chunk . skip ( )