parameters: (self, filename, buffer_size, speaker=None)
docstring: 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.
docstring_summary: 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.
docstring_tokens: 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 .
function: 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)
          if self.auto_scale:
              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:
              msg = "Unexpected sample width {}, can only handle 1, 2 or 4 byte audio"
              raise Exception(msg.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)
function_tokens: def open ( self , filename , buffer_size , speaker = None ) : 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) if self . auto_scale : 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 : msg = "Unexpected sample width {}, can only handle 1, 2 or 4 byte audio" raise Exception ( msg . 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 )