I want to use the PyAudio library in an async context, but the main entry point for the library only has a callback-based API:
import pyaudio
def callback(in_data, frame_count, time_info, status):
# Do something with data
pa = pyaudio.PyAudio()
self.stream = self.pa.open(
stream_callback=callback
)
How I'm hoping to use it is something like this:
pa = SOME_ASYNC_COROUTINE()
async def listen():
async for block in pa:
# Do something with block
The problem is, I'm not sure how to convert this callback syntax to a future that completes when the callback fires. In JavaScript I would use promise.promisify(), but Python doesn't seem to have anything like that.