Use python-rtmixer for low-latency audio recording #119
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Friture has issues keeping up with audio input, which tends to produce overflows, that appear as glitches in the audio signal.
This has largely been unnoticed for years because Windows MME is very forgiveable in that regard. But Windows Directsound, for example, is much more sensitive. Similarly, Alsa or PulseAudio in Linux also show a lot of glitches (even if PortAudio might not report any overflow).
Here this is fixed by taking advantage of python-rtmixer, a library that sits on top of python-sounddevice (the PortAudio wrapper). Python-rtmixer provides an audio callback that is implemented in C and doesn’t invoke the Python interpreter, therefore avoiding waiting for things like garbage collection and the GIL.
Reference: https://python-rtmixer.readthedocs.io/en/0.1.0/index.html
The result is glitch-free audio signal even with Windows DirectSound.
We believe this solves #90