#๐Ÿ”’ Efficient way to wait until something is available in Queue.

7 messages ยท Page 1 of 1 (latest)

warm lintel
#

One python thread is taksed with adding audio into a queue for processing.

while True:
    if not audio_queue.empty():
        audio_chunk = audio_queue.get()
        vad_process(audio_chunk)
    else:
        time.sleep(0.01)

The above is obviously inefficient in resource usage to be constantly checking the queue in realtime.

try:
    audio_chunk = audio_queue.get(timeout=1)
    custom_vad(audio_chunk)
except queue.Empty:
    continue

Is this may be more efficient, but it doesnt seem like the most elegant way to handle waiting for a queue.

Suggestions for a recommended way of handling this?

bronze minnowBOT
#

@warm lintel

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

fiery forum
warm lintel
#

The audio chunks is constantly being streamed from a microphone

#

I need a queue for sometimes where it takes longer than necessary to process each chunk

bronze minnowBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.