The function will block until at least one data chunk is available.
stop = False
while not stop:
// Use a blocking get() to ensure there"s at least one chunk of data.
chunk = buff.get()
data = [chunk]
// Now consume whatever other data"s still buffered.
while True:
try:
data.append(buff.get(block=False))
except queue.Empty:
break
// If `_fill_buffer` adds `None` to the buffer, the audio stream is
// closed. Yield the final bit of the buffer and exit the loop.
if None in data:
stop = True
data.remove(None)
yield b"".join(data)
def _fill_buffer(audio_stream, buff, chunk, stoprequest):