feat: Bluetooth SCO support for microphone recording#857
Open
1d10t wants to merge 5 commits intotermux:masterfrom
Open
feat: Bluetooth SCO support for microphone recording#8571d10t wants to merge 5 commits intotermux:masterfrom
1d10t wants to merge 5 commits intotermux:masterfrom
Conversation
- MicRecorderAPI: extract startRecording() as standalone method, add setupScoAndRecord() with async SCO setup (Android 12+: setCommunicationDevice, older: startBluetoothSco + BroadcastReceiver), add teardownSco() called on stop/error - AudioScoAPI: new API for standalone SCO channel management (enable/disable/status), exposed as termux-audio-sco utility - TermuxApiReceiver: route "AudioSco" to AudioScoAPI - AndroidManifest: add BLUETOOTH, BLUETOOTH_CONNECT, MODIFY_AUDIO_SETTINGS When source=VOICE_COMMUNICATION (7) is passed to MicRecorder, SCO is activated automatically before recording starts and torn down after. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This was referenced Apr 11, 2026
Open
…kVersion to 33 - AudioScoAPI: pass apiReceiver (not context) to ResultReturner.returnData() to prevent unix socket from hanging; reply immediately, setup SCO in background - MicRecorderAPI: fix List<AudioDeviceInfo> type (getAvailableCommunicationDevices returns List, not array); remove postRecordCommandResult from async SCO callbacks - gradle.properties: targetSdkVersion 28 → 33 (required for BLUETOOTH_CONNECT runtime permission grant via pm on Android 12+) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Author
Build & Test ScriptsScripts for building the APK and testing Bluetooth SCO recording are available as a gist: https://gist.github.com/1d10t/2ce712e7b506c529beafb65ca56e84aa Quick start# 1. (First time only) Install Termux debug APK — same signing key as our build
bash 0-install-termux.sh
# 2. Build APK (requires Android SDK + NDK)
bash 1-build-apk.sh
# 3. Install APK and grant permissions via ADB
bash 2-install-apk.sh
# 4. Push updated shell scripts to device
bash 3-install-scripts.sh
# then inside Termux on device, run the cp commands printed by the script
# 5. Test recording from Bluetooth headset (run inside Termux on device)
bash test-bt-mic.shTested on Samsung SM-A325F (Android 12), Bluetooth headset, |
handleEnable now waits for the actual SCO connection result before responding, instead of returning "SCO enable initiated" immediately. Uses CountDownLatch to block the ResultReturner writer thread until the async callback (getProfileProxy on Android 12+, SCO state broadcast on older versions) signals completion. 5-second timeout for pre-12. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ew fixes - Add isScoActive() helper that checks SCO state on both Android 12+ (getCommunicationDevice) and older (isBluetoothScoOn) - handleEnable: early return if SCO already active, skip getProfileProxy - handleDisable: early return if SCO already inactive, skip audio reset - handleStatus: refactored to use shared isScoActive() helper Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ableCommunicationDevices directly Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
source=7(VOICE_COMMUNICATION) is requested, automatically activates Bluetooth SCO before starting recording and tears it down on stop/error. Android 12+:setCommunicationDevice(), older:startBluetoothSco()+BroadcastReceiverwaiting forSCO_AUDIO_STATE_CONNECTED.termux-audio-scoshell utility (see companion termux-api-package PR).BLUETOOTH,BLUETOOTH_CONNECT(Android 12+),MODIFY_AUDIO_SETTINGSpermissions.Usage
Notes
Test plan
termux-microphone-record -s 7records audio from Bluetooth headset microphonetermux-audio-scoreturns JSON statustermux-audio-sco enable/disabletoggles SCO channel-s 1(MIC) still works unchangedtermux-microphone-record -q🤖 Generated with Claude Code