<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def record(self, chunk_size = None, dfmt = "f", channels = 1, rate = DEFAULT_SAMPLE_RATE, **kwargs ):
 """ Records audio from device into a Stream. Parameters chunk_size : Number of samples per chunk (block sent to device). dfmt : Format, as in chunks(). Default is "f" (Float32). channels : Channels in audio stream (serialized). rate : Sample rate (same input used in sHz). Returns ------- Endless Stream instance that gather data from the audio input device. """

    if chunk_size is None:
      chunk_size = chunks.size

    if hasattr(self, "api"):
      kwargs.setdefault("input_device_index", self.api["defaultInputDevice"])

    channels = kwargs.pop("nchannels", channels) # Backwards compatibility

    input_stream = RecStream(self,
                             self._pa.open(format=_STRUCT2PYAUDIO[dfmt],
                                           channels=channels,
                                           rate=rate,
                                           frames_per_buffer=chunk_size,
                                           input=True,
                                           **kwargs),
                             chunk_size,
                             dfmt
                            )
    self._recordings.append(input_stream)
    return input_stream