Main thread function.

def run(self):
		""" Main thread function. """
		if not hasattr(self, 'queue'):
			raise RuntimeError("Audio queue is not intialized.")

		chunk = None
		channel = None
		self.keep_listening = True
		while self.keep_listening:
			if chunk is None:
				try:
					frame = self.queue.get(timeout=queue_timeout)
					chunk = pygame.sndarray.make_sound(frame)
				except Empty:
					continue

			if channel is None:
				channel = chunk.play()
			else:
				if not channel.get_queue():	
					channel.queue(chunk)
					chunk = None
			time.sleep(0.005)
		
		if not channel is None and pygame.mixer.get_init():
			channel.stop()
			pygame.mixer.quit()