Add voice redundancy and the encoder settings on Android
Redundancy sends every voice packet again, one to four times, 20 to 200 ms apart. Listeners' jitter buffers grow to wait for the copies, native clients' included, so a lost packet costs nothing while a copy arrives. With a native client listening over a bursty lossy uplink, the frames lost to concealment fell from 10% to under 1%. Android gets the desktop's encoder settings: bitrate, complexity, VBR, FEC, music codec, and the new redundancy delay and copies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -63,6 +63,8 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
private volatile boolean vadOverPtt;
|
||||
private volatile double inputGain;
|
||||
private volatile CodecType codec = CodecType.OPUS_VOICE;
|
||||
private volatile int redundancyDelay;
|
||||
private volatile int redundancyCopies;
|
||||
|
||||
private final SpeechProbabilityDetector speechDetector =
|
||||
new RnnSpeechDetector(VoiceFormat.SAMPLE_RATE);
|
||||
@@ -109,6 +111,7 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
this.inputGain = settings.inputVolume;
|
||||
this.params = OpusParameters.from(settings);
|
||||
this.codec = codecFor(params);
|
||||
setRedundancy(settings.redundancyDelay, settings.redundancyCopies);
|
||||
processor.setNoiseSuppression(settings.denoise);
|
||||
processor.setSuppressionLevel(SuppressionLevel.fromDenoiserLevel(settings.denoiserLevel));
|
||||
processor.setTransientSuppression(settings.typingAttenuation);
|
||||
@@ -192,6 +195,12 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setRedundancy(int delayMillis, int copies) {
|
||||
this.redundancyDelay = Math.max(0, delayMillis);
|
||||
this.redundancyCopies = Math.max(1, Math.min(Settings.MAX_REDUNDANCY_COPIES, copies));
|
||||
}
|
||||
|
||||
private static OpusCodec.Application applicationFor(OpusParameters p) {
|
||||
return p.music ? OpusCodec.Application.AUDIO : OpusCodec.Application.VOIP;
|
||||
}
|
||||
@@ -551,6 +560,16 @@ public final class CaptureVoiceInput implements VoiceInput {
|
||||
return codec;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRedundancyDelay() {
|
||||
return redundancyDelay;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRedundancyCopies() {
|
||||
return redundancyCopies;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] provide() {
|
||||
byte[] p = queue.poll();
|
||||
|
||||
@@ -66,6 +66,9 @@ public interface VoiceInput extends Microphone {
|
||||
/** Applies Opus encoder parameters, taking effect immediately if capturing. */
|
||||
void setOpusParameters(OpusParameters parameters);
|
||||
|
||||
/** Sends every voice packet {@code copies} more times, {@code delayMillis} apart; a delay of 0 sends it once. */
|
||||
void setRedundancy(int delayMillis, int copies);
|
||||
|
||||
void setPushToTalk(boolean pressed);
|
||||
|
||||
/** Receives the live input level on {@link InputLevel}'s scale, once per captured frame. */
|
||||
@@ -99,5 +102,6 @@ public interface VoiceInput extends Microphone {
|
||||
setAgc(settings.agc);
|
||||
setAgcBoost(settings.agcBoostDb);
|
||||
setOpusParameters(OpusParameters.from(settings));
|
||||
setRedundancy(settings.redundancyDelay, settings.redundancyCopies);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,6 +122,17 @@ public final class Settings {
|
||||
public int packetLoss = 5;
|
||||
/** Encode as music (OPUS_MUSIC) rather than voice (OPUS_VOICE). */
|
||||
public boolean music = false;
|
||||
/**
|
||||
* Milliseconds between a voice packet and each of its {@link #redundancyCopies}, 0 for off.
|
||||
* Listeners' jitter buffers grow to wait for the last copy, so it buys loss resilience with
|
||||
* about {@code redundancyDelay * redundancyCopies} of latency.
|
||||
*/
|
||||
public int redundancyDelay = 0;
|
||||
/** The {@link #redundancyDelay} choices the settings offer; whole 20 ms voice frames. */
|
||||
public static final int[] REDUNDANCY_DELAYS = {0, 20, 40, 60, 80, 120, 200};
|
||||
/** How many times every voice packet is sent again. */
|
||||
public int redundancyCopies = 1;
|
||||
public static final int MAX_REDUNDANCY_COPIES = 4;
|
||||
/** Master playback gain, 0..1 (may exceed 1 for boost up to 2). */
|
||||
public double outputVolume = 1.0;
|
||||
/**
|
||||
@@ -278,6 +289,8 @@ public final class Settings {
|
||||
fec = parseB(props.getProperty("fec"), fec);
|
||||
packetLoss = parseI(props.getProperty("packetLoss"), packetLoss);
|
||||
music = parseB(props.getProperty("music"), music);
|
||||
redundancyDelay = parseI(props.getProperty("redundancyDelay"), redundancyDelay);
|
||||
redundancyCopies = parseI(props.getProperty("redundancyCopies"), redundancyCopies);
|
||||
outputVolume = parseD(props.getProperty("outputVolume"), outputVolume);
|
||||
masterVolume = parseD(props.getProperty("masterVolume"), masterVolume);
|
||||
inputVolume = parseD(props.getProperty("inputVolume"), inputVolume);
|
||||
@@ -336,6 +349,8 @@ public final class Settings {
|
||||
props.setProperty("fec", Boolean.toString(fec));
|
||||
props.setProperty("packetLoss", Integer.toString(packetLoss));
|
||||
props.setProperty("music", Boolean.toString(music));
|
||||
props.setProperty("redundancyDelay", Integer.toString(redundancyDelay));
|
||||
props.setProperty("redundancyCopies", Integer.toString(redundancyCopies));
|
||||
props.setProperty("outputVolume", Double.toString(outputVolume));
|
||||
props.setProperty("masterVolume", Double.toString(masterVolume));
|
||||
props.setProperty("inputVolume", Double.toString(inputVolume));
|
||||
|
||||
Reference in New Issue
Block a user