Keep outgoing voice smooth over long sessions
Drain live mic frames each tick, raise capture priority, and hold a high-performance Wi-Fi lock on Android so power saving stays off in the background. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -40,6 +40,7 @@ class ConnectionService : LifecycleService() {
|
|||||||
|
|
||||||
private lateinit var sessions: SessionController
|
private lateinit var sessions: SessionController
|
||||||
private lateinit var wifiLock: WifiManager.WifiLock
|
private lateinit var wifiLock: WifiManager.WifiLock
|
||||||
|
private lateinit var wifiBackgroundLock: WifiManager.WifiLock
|
||||||
private lateinit var wakeLock: PowerManager.WakeLock
|
private lateinit var wakeLock: PowerManager.WakeLock
|
||||||
private lateinit var overlay: PttOverlay
|
private lateinit var overlay: PttOverlay
|
||||||
private var foregroundTypes = 0
|
private var foregroundTypes = 0
|
||||||
@@ -52,8 +53,13 @@ class ConnectionService : LifecycleService() {
|
|||||||
NotificationChannel(CHANNEL, getString(R.string.connection_channel), NotificationManager.IMPORTANCE_LOW)
|
NotificationChannel(CHANNEL, getString(R.string.connection_channel), NotificationManager.IMPORTANCE_LOW)
|
||||||
)
|
)
|
||||||
// Voice goes out every 20 ms; Wi-Fi power saving and a sleeping CPU would stretch that.
|
// Voice goes out every 20 ms; Wi-Fi power saving and a sleeping CPU would stretch that.
|
||||||
wifiLock = getSystemService(WifiManager::class.java)
|
// Low-latency mode only holds while we are in the foreground with the screen on, so the
|
||||||
.createWifiLock(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, "ts3j:voice")
|
// high-performance lock keeps power saving off the rest of the time.
|
||||||
|
val wifi = getSystemService(WifiManager::class.java)
|
||||||
|
wifiLock = wifi.createWifiLock(WifiManager.WIFI_MODE_FULL_LOW_LATENCY, "ts3j:voice")
|
||||||
|
.apply { setReferenceCounted(false); acquire() }
|
||||||
|
@Suppress("DEPRECATION")
|
||||||
|
wifiBackgroundLock = wifi.createWifiLock(WifiManager.WIFI_MODE_FULL_HIGH_PERF, "ts3j:voice-background")
|
||||||
.apply { setReferenceCounted(false); acquire() }
|
.apply { setReferenceCounted(false); acquire() }
|
||||||
wakeLock = getSystemService(PowerManager::class.java)
|
wakeLock = getSystemService(PowerManager::class.java)
|
||||||
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ts3j:connection")
|
.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "ts3j:connection")
|
||||||
@@ -151,6 +157,7 @@ class ConnectionService : LifecycleService() {
|
|||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
overlay.hide()
|
overlay.hide()
|
||||||
wifiLock.release()
|
wifiLock.release()
|
||||||
|
wifiBackgroundLock.release()
|
||||||
wakeLock.release()
|
wakeLock.release()
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -309,6 +309,8 @@ public final class CaptureVoiceInput implements VoiceInput {
|
|||||||
running.set(true);
|
running.set(true);
|
||||||
captureThread = new Thread(this::captureLoop, "ts3j-mic-capture");
|
captureThread = new Thread(this::captureLoop, "ts3j-mic-capture");
|
||||||
captureThread.setDaemon(true);
|
captureThread.setDaemon(true);
|
||||||
|
// Falling behind overruns the device's buffer, losing audio.
|
||||||
|
captureThread.setPriority(Thread.MAX_PRIORITY);
|
||||||
captureThread.start();
|
captureThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -562,6 +564,11 @@ public final class CaptureVoiceInput implements VoiceInput {
|
|||||||
return transmitting.get() || !queue.isEmpty();
|
return transmitting.get() || !queue.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isLiveCapture() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CodecType getCodec() {
|
public CodecType getCodec() {
|
||||||
return codec;
|
return codec;
|
||||||
|
|||||||
+1
-1
Submodule ts3j updated: a4ce0feb61...2d6f5cdf78
Reference in New Issue
Block a user