How do I consume messages that are available right now in a python generator?

时间:2019-01-09 22:03:03

标签: python generator audio-streaming

I've a audio stream available as a python generator, and a external endpoint that tells if I've to run google speech streaming recognize on the input audio stream.

Is it possible to consume/destroy all messages until now and proceed to transcribe from this point onwards? Something like this:

while disabled:
    time.sleep(30)
    for _ in stream:
        pass
    disabled = check_endpoint()
streaming_transcribe(stream)

1 个答案:

答案 0 :(得分:0)

You can generally handle this with a loop on the generator results:

for message in streaming_transcribe(stream):
    # Process message
    pass
    if check_endpoint(): break