add support for loopback recording on macOS 14.2+ #196
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.
This is my first attempt at integrating loopback recording on Mac as mentioned in #194.
For now, I placed the code necessary to generate the loopback device under the helper class
_CoreAudio. Let me know if you would prefer it having its own helper class.Based on the requirements for this sample project from Apple, I decided to check for loopback support using
platform.mac_verand setting 14.2 as a minimum requirement.With the current implementation, once the user calls
all_microphones(include_loopback=True)for the first time, aloopback deviceis created. Itsidis used as a key in the dictionary_CoreAudio.loopback_deviceswhile theidof thetap objectis stored as its value. Whether or not a device is loopback is determined by its id being present in the dictionary.This id values can be used to destroy the device. I am uncertain whether or not there is a need to actively destroy every device. I set them up to be private which means they are linked to, and only accessible from, the process which created them and from my observations they seem to disappear once the process is stopped.
If I can manage to make process inclusion and exclusion work under cffi, I was thinking the
create_loopback_devicefunction could be exposed to the user to give better control over thetap options. If you think it would be outside the scope of this library let me know.