tools/utilities/pythonlibs/audio/wav_reader.py
def open(self, filename, buffer_size, speaker=None):
        """ open a wav file for reading 
        buffersize   Number of audio samples to return on each read() call
        speaker      Optional output speaker to send converted audio to so you can hear it.
        """
        self.speaker = speaker
        # open a stream on the audio input file.
        self.wav_file = wave.open(filename, "rb")
        self.cvstate = None
        self.read_size = int(buffer_size)
        self.actual_channels = self.wav_file.getnchannels()
        self.actual_rate = self.wav_file.getframerate()
        self.sample_width = self.wav_file.getsampwidth()
        # assumes signed integer used in raw audio, so for example, the max for 16bit is 2^15 (32768)
        self.audio_scale_factor = 1 / pow(2, (8*self.sample_width) - 1)
        if self.requested_rate == 0:
            raise Exception("Requested rate cannot be zero")
        self.buffer_size = int(math.ceil((self.read_size * self.actual_rate) / self.requested_rate))

        # convert int16 data to scaled floats
        if self.sample_width == 1:
            self.dtype = np.int8
        elif self.sample_width == 2:
            self.dtype = np.int16
        elif self.sample_width == 4:
            self.dtype = np.int32
        else:
            raise Exception("Unexpected sample width {}, can only handle 1, 2 or 4 byte audio".format(self.sample_width))

        if speaker:
            # configure output stream to match what we are resampling to...
            audio_format = self.audio.get_format_from_width(self.sample_width)
            speaker.open(audio_format, self.requested_channels, self.requested_rate)
 open a wav file for reading 
        buffersize   Number of audio samples to return on each read() call
        speaker      Optional output speaker to send converted audio to so you can hear it.
        
open a wav file for reading
buffersize   Number of audio samples to return on each read() call
speaker      Optional output speaker to send converted audio to so you can hear it.
open a wav file for reading buffersize Number of audio samples to return on each read () call speaker Optional output speaker to send converted audio to so you can hear it .
def open(self, filename, buffer_size, speaker=None):
        self.speaker = speaker
        self.wav_file = wave.open(filename, "rb")
        self.cvstate = None
        self.read_size = int(buffer_size)
        self.actual_channels = self.wav_file.getnchannels()
        self.actual_rate = self.wav_file.getframerate()
        self.sample_width = self.wav_file.getsampwidth()
        self.audio_scale_factor = 1 / pow(2, (8*self.sample_width) - 1)
        if self.requested_rate == 0:
            raise Exception("Requested rate cannot be zero")
        self.buffer_size = int(math.ceil((self.read_size * self.actual_rate) / self.requested_rate))
        if self.sample_width == 1:
            self.dtype = np.int8
        elif self.sample_width == 2:
            self.dtype = np.int16
        elif self.sample_width == 4:
            self.dtype = np.int32
        else:
            raise Exception("Unexpected sample width {}, can only handle 1, 2 or 4 byte audio".format(self.sample_width))
        if speaker:
            audio_format = self.audio.get_format_from_width(self.sample_width)
            speaker.open(audio_format, self.requested_channels, self.requested_rate)
def open ( self , filename , buffer_size , speaker = None ) : self . speaker = speaker self . wav_file = wave . open ( filename , "rb" ) self . cvstate = None self . read_size = int ( buffer_size ) self . actual_channels = self . wav_file . getnchannels ( ) self . actual_rate = self . wav_file . getframerate ( ) self . sample_width = self . wav_file . getsampwidth ( ) self . audio_scale_factor = 1 / pow ( 2 , ( 8 * self . sample_width ) - 1 ) if self . requested_rate == 0 : raise Exception ( "Requested rate cannot be zero" ) self . buffer_size = int ( math . ceil ( ( self . read_size * self . actual_rate ) / self . requested_rate ) ) if self . sample_width == 1 : self . dtype = np . int8 elif self . sample_width == 2 : self . dtype = np . int16 elif self . sample_width == 4 : self . dtype = np . int32 else : raise Exception ( "Unexpected sample width {}, can only handle 1, 2 or 4 byte audio" . format ( self . sample_width ) ) if speaker : audio_format = self . audio . get_format_from_width ( self . sample_width ) speaker . open ( audio_format , self . requested_channels , self . requested_rate )
open a wav file for reading
buffersize   Number of audio samples to return on each read() call
speaker      Optional output speaker to send converted audio to so you can hear it.
open a wav file for reading buffersize Number of audio samples to return on each read () call speaker Optional output speaker to send converted audio to so you can hear it .
""" open a wav file for reading 
        buffersize   Number of audio samples to return on each read() call
        speaker      Optional output speaker to send converted audio to so you can hear it.
        """ # open a stream on the audio input file. # assumes signed integer used in raw audio, so for example, the max for 16bit is 2^15 (32768) # convert int16 data to scaled floats # configure output stream to match what we are resampling to...
self
filename
buffer_size
speaker