code: def stop(self):
          
          if self.thread:
              self.running = False
              if isinstance(self.stream, ReadWriteStream):
                  self.stream.write(b'\0' * self.chunk_size)
              self.thread.join()
              self.thread = None
  
          self.engine.stop()
  
          if self.pa:
              self.pa.terminate()
              self.stream.stop_stream()
              self.stream = self.pa = None
docs: Stop listening and close stream