mirror of
https://github.com/EchoSixHIYA/WebSpeak-client-for-TeamSpeak.git
synced 2026-12-03 12:02:50 +08:00
feat: add master output volume control
This commit is contained in:
1 parent
335d93a8b8
commit
9bbc22de25
2 files changed
+44
-7
No files matched your search
@@ -137,6 +137,7 @@ export function useVoiceWebSocket() {
|
||||
const microphoneMuted = ref(false);
|
||||
const inputVolume = ref(1);
|
||||
const outputVolume = ref(1);
|
||||
const outputMuted = ref(false);
|
||||
const notificationVolume = ref(0.5);
|
||||
const voxThreshold = ref(0.008);
|
||||
let voxAttack = 0;
|
||||
@@ -232,6 +233,16 @@ export function useVoiceWebSocket() {
|
||||
speakingIds.clear();
|
||||
}
|
||||
|
||||
function effectiveOutputVolume(): number {
|
||||
return outputMuted.value ? 0 : outputVolume.value;
|
||||
}
|
||||
|
||||
function applyOutputVolume(): void {
|
||||
const level = effectiveOutputVolume();
|
||||
for (const [clientId, gain] of remoteGains) gain.gain.value = (volumes[clientId] ?? 1) * level;
|
||||
if (webrtcOutputElement) webrtcOutputElement.volume = level;
|
||||
}
|
||||
|
||||
function getAudioCtx(): SinkAudioContext {
|
||||
if (!audioCtx) {
|
||||
audioCtx = new AudioContext({ sampleRate: 48000 }) as SinkAudioContext;
|
||||
@@ -651,7 +662,7 @@ export function useVoiceWebSocket() {
|
||||
output.autoplay = true;
|
||||
output.muted = false;
|
||||
output.setAttribute("playsinline", "");
|
||||
output.volume = outputVolume.value;
|
||||
output.volume = effectiveOutputVolume();
|
||||
output.setAttribute("aria-hidden", "true");
|
||||
output.tabIndex = -1;
|
||||
output.style.position = "fixed";
|
||||
@@ -929,7 +940,7 @@ export function useVoiceWebSocket() {
|
||||
}
|
||||
|
||||
function playNotification(kind: "connected" | "disconnected" | "poke" | "private" | "reconnectFailed"): void {
|
||||
if (notificationVolume.value <= 0 || typeof window === "undefined") return;
|
||||
if (notificationVolume.value <= 0 || outputMuted.value || effectiveOutputVolume() <= 0 || typeof window === "undefined") return;
|
||||
try {
|
||||
const ctx = getAudioCtx();
|
||||
if (ctx.state === "suspended") return;
|
||||
@@ -946,7 +957,7 @@ export function useVoiceWebSocket() {
|
||||
oscillator.frequency.setValueAtTime(frequencies[kind][0], now);
|
||||
oscillator.frequency.setValueAtTime(frequencies[kind][1], now + 0.08);
|
||||
gain.gain.setValueAtTime(0.0001, now);
|
||||
gain.gain.exponentialRampToValueAtTime(Math.max(0.0001, notificationVolume.value * 0.12), now + 0.01);
|
||||
gain.gain.exponentialRampToValueAtTime(Math.max(0.0001, notificationVolume.value * effectiveOutputVolume() * 0.12), now + 0.01);
|
||||
gain.gain.exponentialRampToValueAtTime(0.0001, now + 0.18);
|
||||
oscillator.connect(gain);
|
||||
gain.connect(ctx.destination);
|
||||
@@ -974,7 +985,7 @@ export function useVoiceWebSocket() {
|
||||
|
||||
if (!decoder) {
|
||||
const gainNode = ctx.createGain();
|
||||
gainNode.gain.value = (volumes[clientId] ?? 1) * outputVolume.value;
|
||||
gainNode.gain.value = (volumes[clientId] ?? 1) * effectiveOutputVolume();
|
||||
gainNode.connect(ctx.destination);
|
||||
remoteGains.set(clientId, gainNode);
|
||||
const generation = ++nextRemoteDecoderGeneration;
|
||||
@@ -1498,7 +1509,7 @@ export function useVoiceWebSocket() {
|
||||
void saveAudioPreferences();
|
||||
}
|
||||
const gain = remoteGains.get(clientId);
|
||||
if (gain) gain.gain.value = normalized * outputVolume.value;
|
||||
if (gain) gain.gain.value = normalized * effectiveOutputVolume();
|
||||
if (webrtcPeer || webrtcActive.value) sendCmd("setMemberVolume", { clientId, volume: normalized });
|
||||
}
|
||||
|
||||
@@ -1520,11 +1531,15 @@ export function useVoiceWebSocket() {
|
||||
|
||||
function setOutputVolume(volume: number): void {
|
||||
outputVolume.value = Math.max(0, Math.min(1, volume));
|
||||
for (const [clientId, gain] of remoteGains) gain.gain.value = (volumes[clientId] ?? 1) * outputVolume.value;
|
||||
if (webrtcOutputElement) webrtcOutputElement.volume = outputVolume.value;
|
||||
applyOutputVolume();
|
||||
void saveAudioPreferences();
|
||||
}
|
||||
|
||||
function toggleOutputMute(): void {
|
||||
outputMuted.value = !outputMuted.value;
|
||||
applyOutputVolume();
|
||||
}
|
||||
|
||||
function setVoxThreshold(threshold: number): void {
|
||||
voxThreshold.value = clamp(threshold, 0.001, 0.08);
|
||||
void saveAudioPreferences();
|
||||
@@ -1546,6 +1561,7 @@ export function useVoiceWebSocket() {
|
||||
microphoneMuted,
|
||||
inputVolume,
|
||||
outputVolume,
|
||||
outputMuted,
|
||||
notificationVolume,
|
||||
voxThreshold,
|
||||
inputDevices,
|
||||
@@ -1569,6 +1585,7 @@ export function useVoiceWebSocket() {
|
||||
setVolume,
|
||||
setInputVolume,
|
||||
setOutputVolume,
|
||||
toggleOutputMute,
|
||||
setVoxThreshold,
|
||||
setNotificationVolume,
|
||||
prepareInputDevices,
|
||||
|
||||
@@ -213,6 +213,10 @@
|
||||
<div class="desktop-audio-dock-copy"><strong>{{ t('desktopAudioControls') }}</strong><span>{{ accompanimentActive ? t('accompanimentActive') : t('volumeTip') }}</span></div>
|
||||
<div class="desktop-audio-dock-actions">
|
||||
<button type="button" class="dock-audio-button microphone-header-toggle" :class="{ muted: microphoneMuted }" :title="microphoneMuted ? t('unmuteMic') : t('muteMic')" :aria-label="microphoneMuted ? t('microphoneMuted') : t('microphoneActive')" :aria-pressed="!microphoneMuted" @click="toggleMicrophone"><Icon :name="microphoneMuted ? 'mic-off' : 'mic'" :size="18" /></button>
|
||||
<div class="dock-output-control">
|
||||
<button type="button" class="dock-audio-button" :class="{ muted: outputMuted }" :title="outputMuted ? t('unmuteOutput') : t('muteOutput')" :aria-label="outputMuted ? t('unmuteOutput') : t('muteOutput')" :aria-pressed="!outputMuted" @click="toggleOutputMute"><Icon :name="outputMuted ? 'volume-off' : 'volume'" :size="18" /></button>
|
||||
<input class="dock-output-slider" type="range" min="0" max="100" :value="outputVolume * 100" :style="rangeStyle(outputVolume, 1)" :aria-label="t('overallVolume')" @input="onOutputVolume" />
|
||||
</div>
|
||||
<button type="button" class="dock-audio-button" :title="t('audioSettings')" :aria-label="t('audioSettings')" @click="settingsOpen = true"><Icon name="settings" :size="18" /></button>
|
||||
<button type="button" class="dock-audio-button accompaniment-toggle" :class="{ active: accompanimentActive }" :title="accompanimentActive ? t('stopAccompaniment') : t('startAccompaniment')" :aria-label="accompanimentActive ? t('stopAccompaniment') : t('startAccompaniment')" :aria-pressed="accompanimentActive" @click="toggleAccompaniment"><Icon name="music" :size="18" /></button>
|
||||
</div>
|
||||
@@ -301,6 +305,7 @@ const {
|
||||
microphoneMuted,
|
||||
inputVolume,
|
||||
outputVolume,
|
||||
outputMuted,
|
||||
notificationVolume,
|
||||
voxThreshold,
|
||||
inputDevices,
|
||||
@@ -321,6 +326,7 @@ const {
|
||||
setVolume,
|
||||
setInputVolume,
|
||||
setOutputVolume,
|
||||
toggleOutputMute,
|
||||
setVoxThreshold,
|
||||
setNotificationVolume,
|
||||
prepareInputDevices,
|
||||
@@ -474,6 +480,9 @@ const translations: Record<string, Record<string, string>> = {
|
||||
serverOptions: "更多服务器选项",
|
||||
online: "在线",
|
||||
audioSettings: "音频设置",
|
||||
overallVolume: "整体音量",
|
||||
muteOutput: "临时静音",
|
||||
unmuteOutput: "恢复声音",
|
||||
desktopAudioControls: "音频控制",
|
||||
startAccompaniment: "共享伴奏",
|
||||
stopAccompaniment: "停止伴奏",
|
||||
@@ -716,6 +725,9 @@ const translations: Record<string, Record<string, string>> = {
|
||||
serverOptions: "More server options",
|
||||
online: "Online",
|
||||
audioSettings: "Audio settings",
|
||||
overallVolume: "Master volume",
|
||||
muteOutput: "Mute all audio",
|
||||
unmuteOutput: "Restore audio",
|
||||
desktopAudioControls: "Audio controls",
|
||||
startAccompaniment: "Share accompaniment",
|
||||
stopAccompaniment: "Stop accompaniment",
|
||||
@@ -961,6 +973,9 @@ translations.de = {
|
||||
serverOptions: "Weitere Serveroptionen",
|
||||
online: "Online",
|
||||
audioSettings: "Audioeinstellungen",
|
||||
overallVolume: "Gesamtlautstärke",
|
||||
muteOutput: "Alle Töne stummschalten",
|
||||
unmuteOutput: "Ton wiederherstellen",
|
||||
desktopAudioControls: "Audiosteuerung",
|
||||
startAccompaniment: "Begleitung teilen",
|
||||
stopAccompaniment: "Begleitung stoppen",
|
||||
@@ -2090,9 +2105,14 @@ function stopWhisperTalk(): void {
|
||||
.desktop-audio-dock-copy strong { overflow: hidden; color: var(--text-primary); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.desktop-audio-dock-copy span { overflow: hidden; font-size: 10px; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.desktop-audio-dock-actions { display: flex; align-items: center; gap: 4px; flex: 0 0 auto; }
|
||||
.dock-output-control { display: flex; align-items: center; gap: 5px; }
|
||||
.dock-output-slider { width: 76px; height: 5px; appearance: none; border-radius: 999px; outline: none; cursor: pointer; }
|
||||
.dock-output-slider::-webkit-slider-thumb { width: 14px; height: 14px; appearance: none; border: 2px solid #81d8d0; border-radius: 50%; background: var(--surface-1); cursor: pointer; }
|
||||
.dock-output-slider::-moz-range-thumb { width: 14px; height: 14px; border: 2px solid #81d8d0; border-radius: 50%; background: var(--surface-1); cursor: pointer; }
|
||||
.dock-audio-button { display: grid; place-items: center; width: 34px; height: 34px; padding: 0; color: var(--text-muted); background: transparent; border: 1px solid transparent; border-radius: 9px; cursor: pointer; transition: color .16s, background .16s, border-color .16s, transform .16s; }
|
||||
.dock-audio-button:hover, .dock-audio-button:focus-visible { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, var(--surface-1)); border-color: color-mix(in srgb, var(--accent) 32%, var(--border)); transform: translateY(-1px); }
|
||||
.dock-audio-button.microphone-header-toggle.muted { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface-1)); }
|
||||
.dock-audio-button.muted { color: var(--danger); background: color-mix(in srgb, var(--danger) 12%, var(--surface-1)); }
|
||||
.dock-audio-button.accompaniment-toggle.active { color: var(--accent); background: color-mix(in srgb, var(--accent) 18%, var(--surface-1)); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 12%, transparent); }
|
||||
.settings-mode-switch { width: fit-content; margin: 0 0 7px; }
|
||||
.settings-hint { margin: -1px 0 19px; color: #8b9994; font-size: 11px; }
|
||||
|
||||
Reference in new issue
Block a user