big-school-62939
05/14/2026, 4:46 PMtall-airline-16756
05/14/2026, 4:46 PMtall-airline-16756
05/14/2026, 4:46 PMremoteTrackPublication.SetSubscribed(false)
◦ When they move outside the threshold, re-subscribe: remoteTrackPublication.SetSubscribed(true)
Notes and tips:
• This is client-side: each client decides which remote tracks to subscribe to.
• You can toggle subscription on per-participant or per-track basis to preserve other data (video, data channels).
• If you need spatial rendering (positional audio), that’s a separate step — LiveKit examples show using WebAudio PannerNodes for spatialization in web builds; in Unity you’d apply Unity’s audio spatialization while still controlling subscription as above.
If you’d like, tell me:
• Which Unity LiveKit SDK version you’re using, and
• Whether you want strict mute (unsubscribe) or just attenuate volume (apply Unity audio volume scaling)
— and I’ll give exact code snippets for your choice.
Sources: Using WebRTC + React + WebAudio to create spatial audio | LiveKit | Real-time audio and video in the metaverse | LiveKit, with interactive elementsbig-school-62939
05/14/2026, 4:47 PMtall-airline-16756
05/14/2026, 4:47 PMbig-school-62939
05/14/2026, 4:51 PMtall-airline-16756
05/14/2026, 4:51 PMbig-school-62939
05/14/2026, 4:55 PMtall-airline-16756
05/14/2026, 4:55 PMbig-school-62939
05/14/2026, 4:58 PMtall-airline-16756
05/14/2026, 4:58 PMandroid.media.audiofx.NoiseSuppressor) or
• Integrating a third‑party SDK (e.g., RNNoise/Krisp-like plugins) or
• Using Unity WebRTC's audio processing if you already use that., with interactive elementsbig-school-62939
05/14/2026, 5:02 PMtall-airline-16756
05/14/2026, 5:02 PMUnityEngine.Microphone.
Short summary: UnityEngine.Microphone does not expose Android’s platform audio effects. To use Android’s NoiseSuppressor you need to capture audio via a native Android AudioRecord that attaches a NoiseSuppressor, read PCM frames, then feed those frames into LiveKit as a local audio track. Below are the high-level steps and a minimal example flow with guidance on permissions, sample rates, and integration points.
Steps overview
1. Add RECORD_AUDIO permission to AndroidManifest and request it at runtime.
2. Implement an Android Java/Kotlin plugin that:
◦ Creates an AudioRecord with your desired sample rate/channel config.
◦ Attaches NoiseSuppressor.create(audioSessionId) to the AudioRecord session.
◦ Reads PCM buffers in a background thread and exposes them via a JNI call or a Unity callback (e.g., using UnityPlayer.UnitySendMessage) or a shared native buffer.
1. In Unity C#:
◦ Call the plugin to start/stop capture.
◦ Receive PCM frames from the plugin, convert to the format LiveKit expects, and send them into LiveKit as a local audio source (e.g., via a RawAudioSource/local audio track API).
1. Ensure sample rate and channel layout match LiveKit expectations (typically 48 kHz mono/stereo) and perform resampling if necessary.
2. Test and tune buffer sizes and thread scheduling for low latency.
Key implementation notes
• Android API: use android.media.AudioRecord + android.media.audiofx.NoiseSuppressor (requires API level where NoiseSuppressor is available; check device compatibility).
• Permissions: add <uses-permission android:name="android.permission.RECORD_AUDIO"/> and request at runtime on Android 6.0+.
• Audio session: create AudioRecord, call int sessionId = audioRecord.getAudioSessionId(), then NoiseSuppressor.create(sessionId).
• Buffering: pick a buffer size using AudioRecord.getMinBufferSize() and read repeatedly on a dedicated thread.
• Threading: deliver PCM to Unity on a thread-safe pathway (avoid blocking Unity main thread).
• Format: Android AudioRecord usually gives 16-bit PCM; LiveKit SDKs accept PCM float/int16 depending on integration — convert accordingly.
Minimal Java plugin pseudocode (concept)
// Create AudioRecord and NoiseSuppressor
int sampleRate = 48000;
int channelConfig = AudioFormat.CHANNEL_IN_MONO;
int audioFormat = AudioFormat.ENCODING_PCM_16BIT;
int minBuf = AudioRecord.getMinBufferSize(sampleRate, channelConfig, audioFormat);
AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.VOICE_COMMUNICATION,
sampleRate, channelConfig, audioFormat, minBuf);
int sessionId = recorder.getAudioSessionId();
NoiseSuppressor ns = NoiseSuppressor.create(sessionId); // enable NS
recorder.startRecording();
byte[] buffer = new byte[minBuf];
while (running) {
int read = recorder.read(buffer, 0, buffer.length);
if (read > 0) {
// send buffer to Unity via JNI/UnitySendMessage or write to native circular buffer
}
}
recorder.stop();
ns.release();
recorder.release();
Unity-side options to feed LiveKit
• If LiveKit Unity SDK accepts a custom audio source/track API (raw PCM callback), push the processed PCM into that API to create the LocalAudioTrack.
• If the SDK doesn’t provide a raw-pcm hook, create a bridge that feeds processed audio into an AudioClip using `AudioClip.SetData`/`OnAudioRead` and capture that clip as the microphone source for LiveKit (note: extra latency).
• Ensure you convert 16-bit PCM to float [-1..1] if the Unity/LiveKit API expects floats.
Alternative (simpler) options
• Use platform-level voice-optimized audio source: when creating AudioRecord, use MediaRecorder.AudioSource.VOICE_COMMUNICATION or VOICE_RECOGNITION which enables some OS processing automatically. This may reduce bleed without custom NoiseSuppressor handling.
• Use a third-party noise-suppression native library (RNNoise, WebRTC AEC/NS modules, or commercial SDKs) integrated similarly: run native processing on the AudioRecord frames, then forward processed frames into Unity/LiveKit.
• If implementing full native pipeline is heavy, require headsets or recommend OS/driver noise cancellation as a short-term mitigation.
Would you like:
• A complete Unity + Java plugin example with code files (Java plugin, JNI shims, Unity C# receiver) to copy into your project, or
• A smaller example showing only the Android plugin and how to test it first (so you can verify suppression), or
• Recommendations for third-party libraries and integration notes?
Tell me which and I’ll provide the exact code/files for that path.
, with interactive elementsbig-school-62939
05/14/2026, 5:27 PMtall-airline-16756
05/14/2026, 5:27 PMandroid.media.audiofx.NoiseSuppressor class was added in Android API level 16 (Android 4.1, Jelly Bean).
Android docs: https://developer.android.com/reference/android/media/audiofx/NoiseSuppressor
, with interactive elements