{"id":30039826,"url":"https://github.com/twilio/audioswitch","last_synced_at":"2025-08-07T01:52:11.692Z","repository":{"id":37078089,"uuid":"258318701","full_name":"twilio/audioswitch","owner":"twilio","description":"An Android audio management library for real-time communication apps.","archived":false,"fork":false,"pushed_at":"2025-06-28T00:15:10.000Z","size":3710,"stargazers_count":182,"open_issues_count":10,"forks_count":53,"subscribers_count":22,"default_branch":"master","last_synced_at":"2025-06-28T00:26:12.692Z","etag":null,"topics":["android","android-audio","audio","audio-devices","bluetooth-headset","communication-apps","java","kotlin","twilio","video","voice","webrtc"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/twilio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-04-23T20:10:04.000Z","updated_at":"2025-06-12T07:03:17.000Z","dependencies_parsed_at":"2024-03-21T13:27:57.606Z","dependency_job_id":"8f7b96d1-b443-496a-9ef2-a98b2cdd2e45","html_url":"https://github.com/twilio/audioswitch","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/twilio/audioswitch","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilio%2Faudioswitch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilio%2Faudioswitch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilio%2Faudioswitch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilio%2Faudioswitch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/twilio","download_url":"https://codeload.github.com/twilio/audioswitch/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/twilio%2Faudioswitch/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269185779,"owners_count":24374633,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-06T02:00:09.910Z","response_time":99,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-audio","audio","audio-devices","bluetooth-headset","communication-apps","java","kotlin","twilio","video","voice","webrtc"],"created_at":"2025-08-07T01:52:10.521Z","updated_at":"2025-08-07T01:52:11.675Z","avatar_url":"https://github.com/twilio.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# AudioSwitch\n\n[![CircleCI](https://circleci.com/gh/twilio/audioswitch.svg?style=svg)](https://circleci.com/gh/twilio/audioswitch)\n\nAn Android audio management library for real-time communication apps.\n\n![video-app-screenshots](images/audioswitch-logo.png)\n\n## Features\n\n- [x] Manage [audio focus](https://developer.android.com/guide/topics/media-apps/audio-focus) for typical VoIP and Video conferencing use cases.\n- [x] Manage audio input and output devices.\n    - [x] Detect changes in available audio devices\n    - [x] Enumerate audio devices\n    - [x] Select an audio device\n\n## Requirements\n\nAndroid Studio Version | Android API Version Min\n------------ | -------------\n3.6+ | 16\n\n## Documentation\n\nThe KDoc for this library can be found [here](https://twilio.github.io/audioswitch/latest).\n\n## Getting Started\n\nTo get started using this library, follow the steps below.\n\n### Gradle Setup\n\n[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.twilio/audioswitch/badge.svg) ](https://maven-badges.herokuapp.com/maven-central/com.twilio/audioswitch)\n\nEnsure that you have `mavenCentral` listed in your project's buildscript repositories section:\n```groovy\nbuildscript {\n    repositories {\n        mavenCentral()\n        // ...\n    }\n}\n```\n\nAdd this line as a new Gradle dependency:\n```groovy\nimplementation 'com.twilio:audioswitch:$version'\n```\n\nPull requests merged to master result in a snapshot artifact being published to the Maven Central snapshots repository. You can\naccess these snapshots by adding the following to your gradle file `repositories`:\n\n```groovy\nmaven {\n    url = uri(\"https://oss.sonatype.org/content/repositories/snapshots\")\n}\n```\n\nAdd a `-SNAPSHOT` suffix to the Gradle dependency version:\n\n```groovy\nimplementation 'com.twilio:audioswitch:$version-SNAPSHOT'\n```\n\n### AudioSwitch Setup\nInstantiate an instance of the [AudioSwitch](audioswitch/src/main/java/com/twilio/audioswitch/AudioSwitch.kt) class, passing a reference to the application context.\n\n```kotlin\nval audioSwitch = AudioSwitch(applicationContext)\n```\n\n### Listen for Devices\nTo begin listening for live audio device changes, call the start function and pass a lambda that will receive [AudioDevices](audioswitch/src/main/java/com/twilio/audioswitch/AudioDevice.kt) when they become available.\n\n```kotlin\naudioSwitch.start { audioDevices, selectedDevice -\u003e\n    // TODO update UI with audio devices\n}\n```\nYou can also retrieve the available and selected audio devices manually at any time by calling the following properties:\n```kotlin\nval devices: List\u003cAudioDevice\u003e = audioSwitch.availableAudioDevices\nval selectedDevice: AudioDevice? = audioSwitch.selectedAudioDevice\n```\n**Note:** Don't forget to stop listening for audio devices when no longer needed in order to prevent a memory leak.\n```kotlin\naudioSwitch.stop()\n```\n\n### Select a Device\nBefore activating an AudioDevice, it needs to be selected first.\n```kotlin\ndevices.find { it is AudioDevice.Speakerphone }?.let { audioSwitch.selectDevice(it) }\n```\nIf no device is selected, then the library will automatically select a device based on the following priority: `BluetoothHeadset -\u003e WiredHeadset -\u003e Earpiece -\u003e Speakerphone`.\n\n### Activate a Device\nActivating a device acquires audio focus with [voice communication usage](https://developer.android.com/reference/android/media/AudioAttributes#USAGE_VOICE_COMMUNICATION) and begins routing audio input/output to the selected device.\n```kotlin\naudioSwitch.activate()\n```\nMake sure to revert back to the prior audio state when it makes sense to do so in your app.\n```kotlin\naudioSwitch.deactivate()\n```\n**Note:** The `stop()` function will call `deactivate()` before closing AudioSwitch resources.\n\n## Bluetooth Support\n\nMultiple connected bluetooth headsets are supported.\n  - Bluetooth support requires BLUETOOTH_CONNECT or BLUETOOTH permission. These permission have to be added to the application using AudioSwitch, they do not come with the library.\n  - The library will accurately display the up to date active bluetooth headset within the `AudioSwitch` `availableAudioDevices` and `selectedAudioDevice` functions.\n    - Other connected headsets are not stored by the library at this moment.\n  - In the event of a failure to connecting audio to a bluetooth headset, the library will revert the selected audio device (this is usually the Earpiece on a phone).\n    - Additionally [BluetoothHeadsetConnectionListener](audioswitch/src/main/java/com/twilio/audioswitch/bluetooth/BluetoothHeadsetConnectionListener.kt) can be provided to AudioSwitch constructor to monitor state changes and connection failures.\n  - If a user would like to switch between multiple Bluetooth headsets, then they need to switch the active bluetooth headset from the system Bluetooth settings.\n    - The newly activated headset will be propagated to the `AudioSwitch` `availableAudioDevices` and `selectedAudioDevice` functions.\n\n## Java Compatibility\n\nAudioswitch is compatible with apps written in Java that [target Java 8](https://developer.android.com/studio/write/java8-support), and follows the recommendations provided in the [Kotlin for Java consumption guide](https://developer.android.com/kotlin/interop#kotlin_for_java_consumption). The project includes [Java specific unit tests](https://github.com/twilio/audioswitch/tree/master/audioswitch/src/test/java/com/twilio/audioswitch) that demonstrate how to use Audioswitch from a Java based application. If you have any Java compatibility questions please [open an issue](https://github.com/twilio/audioswitch/issues).\n\n## Logging\n\nBy default, AudioSwitch logging is disabled. Reference the following snippet to enable AudioSwitch logging:\n\n```kotlin\nval audioSwitch = AudioSwitch(context, loggingEnabled = true)\n\naudioSwitch.start { _, _ -\u003e }\n```\n\n## Permissions\nOn Android 12 and greater, the application using this library is expected to request the BLUETOOTH_CONNECT permission. Not doing so will disable the use of bluetooth in the audioswitch library.\nPre-Android 12, no user permission requests are needed. All other permissions needed are listed in the library's manifest and are automatically merged from the [manifest file](audioswitch/src/main/AndroidManifest.xml) in this library.\n\n## Contributing\n\nWe welcome and encourage contributions to AudioSwitch! However, pull request (PR) validation requires access to credentials that we cannot provide to external contributors. As a result, the contribution process is as follows:\n\n1. Submit a PR from a fork with your changes\n1. Our team will review\n1. If the changes are small enough and do not require validation (eg. documentation typo) we will merge your PR directly.\n1. If the changes require integration testing, then, once approved, our team will close your PR and create a new PR from a branch on the main repository and reference your original work.\n1. Our team will handle merging the final PR and releasing a new version with your changes.\n1. (Optional) Submit a PR that adds you to our [CONTRIBUTORS](CONTRIBUTORS.md) file so you show up on the [contributors page](https://github.com/twilio/audioswitch/graphs/contributors).\n\n## Usage Examples\n\n* [Twilio Video Android App](https://github.com/twilio/twilio-video-app-android)\n* [Twilio Video Android Quickstart](https://github.com/twilio/video-quickstart-android)\n* [Twilio Voice Android Quickstart](https://github.com/twilio/voice-quickstart-android)\n\n## License\n\nApache 2.0 license. See [LICENSE.txt](LICENSE.txt) for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilio%2Faudioswitch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftwilio%2Faudioswitch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftwilio%2Faudioswitch/lists"}