Skip to content

Commit e94c739

Browse files
Robclaude
andcommitted
fix(audio): show intensity profile for sound-only alerts; enforce TTS min volume
- CommonAlertSettings: intensity profile (SOFT/STEADY/STRONG/ESCALATING) was hidden behind vibration toggle; now shown whenever sound OR vibration is enabled, since it controls both sound ceiling and haptic amplitude. Label changed from "Haptics" to "Intensity" to reflect dual role. - Talker: add ensureMinStreamVolume() called before every engine.speak(). If the active stream (notification/media/alarm) is below 25% of its max, it is raised to that floor before speaking. Prevents spoken readings from going silent when the user sets media volume to zero. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 200b786 commit e94c739

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

Common/src/main/java/tk/glucodata/Talker.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,9 +479,37 @@ public void onStart(String utteranceId) {
479479
}
480480
}
481481

482+
// Fraction of the stream's max volume that is the minimum allowed for TTS output.
483+
// Prevents silence when the user (or system) drives the stream to zero.
484+
private static final float MIN_TTS_VOLUME_FRACTION = 0.25f;
485+
486+
private static int usageToStreamType(int usage) {
487+
switch (usage) {
488+
case AudioAttributes.USAGE_ALARM: return AudioManager.STREAM_ALARM;
489+
case AudioAttributes.USAGE_MEDIA: return AudioManager.STREAM_MUSIC;
490+
default: return AudioManager.STREAM_NOTIFICATION;
491+
}
492+
}
493+
494+
private static void ensureMinStreamVolume() {
495+
try {
496+
AudioManager am = (AudioManager) Applic.app.getSystemService(Context.AUDIO_SERVICE);
497+
if (am == null) return;
498+
final int stream = usageToStreamType(Natives.getSoundType());
499+
final int maxVol = am.getStreamMaxVolume(stream);
500+
final int minVol = Math.max(1, Math.round(maxVol * MIN_TTS_VOLUME_FRACTION));
501+
if (am.getStreamVolume(stream) < minVol) {
502+
am.setStreamVolume(stream, minVol, 0);
503+
}
504+
} catch (Throwable th) {
505+
Log.stack(LOG_ID, "ensureMinStreamVolume", th);
506+
}
507+
}
508+
482509
public void speak(String message) {
483510
if(!DontTalk) {
484511
try {
512+
ensureMinStreamVolume();
485513
if(
486514
((android.os.Build.VERSION.SDK_INT >= 21)?
487515
engine.speak(message, TextToSpeech.QUEUE_FLUSH, null,message):

Common/src/mobile/java/tk/glucodata/ui/alerts/CommonAlertSettings.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ fun CommonAlertSettings(
135135
unselectedContentColor = MaterialTheme.colorScheme.onPrimaryContainer
136136
)
137137

138-
AnimatedVisibility(visible = config.vibrationEnabled) {
138+
AnimatedVisibility(visible = config.soundEnabled || config.vibrationEnabled) {
139139
Column(verticalArrangement = Arrangement.spacedBy(6.dp)) {
140140
Text(
141-
text = stringResource(R.string.haptics),
141+
text = stringResource(R.string.intensity),
142142
style = MaterialTheme.typography.labelLarge,
143143
color = MaterialTheme.colorScheme.onSurfaceVariant
144144
)

0 commit comments

Comments
 (0)