V1
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
/* Contrôles indépendants de la feuille alfred.css existante */
|
||||
body > main { position: relative; min-height: 100dvh; padding-bottom: 82px; box-sizing: border-box; }
|
||||
.alfred-controls {
|
||||
position: absolute; left: 16px; right: 16px; bottom: 12px;
|
||||
display: flex; align-items: center; gap: 14px; min-height: 56px;
|
||||
padding: 8px 18px; box-sizing: border-box;
|
||||
border: 1px solid rgba(255,255,255,.10); border-radius: 16px;
|
||||
background: rgba(35,37,41,.92); color: #f4f4f5;
|
||||
box-shadow: 0 8px 28px rgba(0,0,0,.14);
|
||||
font: 14px/1.3 system-ui, sans-serif;
|
||||
}
|
||||
.alfred-controls .audio-toggle { flex: 0 0 auto; width: 42px; height: 42px; padding: 0; border: 1px solid transparent; border-radius: 12px; background: transparent; color: inherit; font-size: 23px; cursor: pointer; }
|
||||
.alfred-controls .audio-toggle:hover, .alfred-controls .audio-toggle:focus-visible { background: rgba(255,255,255,.10); outline-offset: 2px; }
|
||||
.alfred-controls .audio-toggle[aria-pressed="true"] { background: rgba(225,100,100,.14); border-color: rgba(225,100,100,.28); }
|
||||
.alfred-controls .volume-label { white-space: nowrap; color: #c8c8ce; }
|
||||
.alfred-controls input[type="range"] { min-width: 60px; flex: 1; accent-color: #d1d5db; cursor: pointer; }
|
||||
.alfred-controls output { min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; }
|
||||
.alfred-controls .controls-separator { height: 25px; width: 1px; background: rgba(255,255,255,.16); }
|
||||
@media (max-width: 480px) { .alfred-controls { gap: 8px; padding: 6px 9px; left: 8px; right: 8px; } .alfred-controls .volume-label { display: none; } }
|
||||
@@ -0,0 +1,73 @@
|
||||
(() => {
|
||||
'use strict';
|
||||
const slider = document.getElementById('volumeSlider');
|
||||
const volumeValue = document.getElementById('volumeValue');
|
||||
const speaker = document.getElementById('speakerMute');
|
||||
const mic = document.getElementById('micMute');
|
||||
const endpoint = '/api/audio/settings';
|
||||
let state = { volume: 70, speaker_muted: false, mic_muted: false };
|
||||
let saveTimer;
|
||||
|
||||
function render() {
|
||||
slider.value = String(state.volume);
|
||||
volumeValue.value = `${state.volume} %`;
|
||||
speaker.setAttribute('aria-pressed', String(state.speaker_muted));
|
||||
speaker.setAttribute('aria-label', state.speaker_muted ? 'Réactiver le haut-parleur' : 'Couper le haut-parleur');
|
||||
speaker.title = speaker.getAttribute('aria-label');
|
||||
speaker.textContent = state.speaker_muted ? '🔇' : '🔊';
|
||||
mic.setAttribute('aria-pressed', String(state.mic_muted));
|
||||
mic.setAttribute('aria-label', state.mic_muted ? 'Réactiver le microphone' : 'Couper le microphone');
|
||||
mic.title = mic.getAttribute('aria-label');
|
||||
mic.textContent = state.mic_muted ? '🎙️̸' : '🎙️';
|
||||
}
|
||||
|
||||
async function save() {
|
||||
try {
|
||||
const response = await fetch(endpoint, {
|
||||
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(state)
|
||||
});
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const result = await response.json();
|
||||
if (result && typeof result.volume === 'number') {
|
||||
state = { ...state, ...result };
|
||||
render();
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn('Réglages audio non synchronisés avec Flask :', error);
|
||||
}
|
||||
}
|
||||
|
||||
slider.addEventListener('input', () => {
|
||||
state.volume = Number(slider.value);
|
||||
render();
|
||||
clearTimeout(saveTimer);
|
||||
saveTimer = setTimeout(save, 200);
|
||||
});
|
||||
speaker.addEventListener('click', () => {
|
||||
state.speaker_muted = !state.speaker_muted;
|
||||
render();
|
||||
clearTimeout(saveTimer);
|
||||
save();
|
||||
});
|
||||
mic.addEventListener('click', () => {
|
||||
state.mic_muted = !state.mic_muted;
|
||||
render();
|
||||
clearTimeout(saveTimer);
|
||||
save();
|
||||
});
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
const response = await fetch(endpoint);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const settings = await response.json();
|
||||
if (typeof settings.volume === 'number') state.volume = Math.max(0, Math.min(100, settings.volume));
|
||||
if (typeof settings.speaker_muted === 'boolean') state.speaker_muted = settings.speaker_muted;
|
||||
if (typeof settings.mic_muted === 'boolean') state.mic_muted = settings.mic_muted;
|
||||
} catch (error) {
|
||||
console.warn('Réglages audio non disponibles :', error);
|
||||
}
|
||||
render();
|
||||
})();
|
||||
})();
|
||||
@@ -0,0 +1,62 @@
|
||||
"""Réglages audio Alfred : ALSA carte 1 et états logiques thread-safe."""
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
import threading
|
||||
|
||||
_LOCK = threading.RLock()
|
||||
_STATE = {'volume': 70, 'speaker_muted': False, 'mic_muted': False}
|
||||
_CARD = os.getenv('ALFRED_ALSA_CARD', '1')
|
||||
_CONTROL = os.getenv('ALFRED_ALSA_VOLUME_CONTROL', 'Master')
|
||||
|
||||
def _amixer(*args):
|
||||
return subprocess.run(['amixer', '-c', _CARD, *args], capture_output=True,
|
||||
text=True, timeout=5, check=True).stdout
|
||||
|
||||
def initialize():
|
||||
"""Lit le volume existant sans modifier les réglages audio au démarrage."""
|
||||
try:
|
||||
output = _amixer('sget', _CONTROL)
|
||||
matches = re.findall(r'\[(\d+)%\]', output)
|
||||
with _LOCK:
|
||||
if matches:
|
||||
_STATE['volume'] = int(matches[0])
|
||||
# Ne pas déduire speaker_muted du mixer : état propre à Alfred.
|
||||
except (OSError, subprocess.SubprocessError) as exc:
|
||||
print(f'[ALFRED AUDIO] Lecture ALSA impossible : {exc}', flush=True)
|
||||
|
||||
def get_settings():
|
||||
with _LOCK:
|
||||
return dict(_STATE)
|
||||
|
||||
def update_settings(payload):
|
||||
if not isinstance(payload, dict):
|
||||
raise ValueError('Un objet JSON est attendu')
|
||||
allowed = {'volume', 'speaker_muted', 'mic_muted'}
|
||||
if set(payload) - allowed:
|
||||
raise ValueError('Paramètre audio inconnu')
|
||||
with _LOCK:
|
||||
new = dict(_STATE)
|
||||
if 'volume' in payload:
|
||||
v = payload['volume']
|
||||
if isinstance(v, bool) or not isinstance(v, (int, float)) or not 0 <= v <= 100:
|
||||
raise ValueError('volume doit être entre 0 et 100')
|
||||
new['volume'] = round(v)
|
||||
for key in ('speaker_muted', 'mic_muted'):
|
||||
if key in payload:
|
||||
if not isinstance(payload[key], bool):
|
||||
raise ValueError(f'{key} doit être un booléen')
|
||||
new[key] = payload[key]
|
||||
# Ne touche jamais aux contrôles Mic/Capture : calibration conservée.
|
||||
if new['volume'] != _STATE['volume']:
|
||||
_amixer('sset', _CONTROL, f"{new['volume']}%")
|
||||
_STATE.update(new)
|
||||
return dict(_STATE)
|
||||
|
||||
def speaker_muted():
|
||||
with _LOCK:
|
||||
return _STATE['speaker_muted']
|
||||
|
||||
def mic_muted():
|
||||
with _LOCK:
|
||||
return _STATE['mic_muted']
|
||||
@@ -0,0 +1,28 @@
|
||||
<!doctype html>
|
||||
<html lang="fr">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>{{name}}</title>
|
||||
<link rel="stylesheet" href="/static/css/alfred.css">
|
||||
<link rel="stylesheet" href="/static/css/alfred-controls.css">
|
||||
<script src="https://cdn.socket.io/4.7.5/socket.io.min.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<header><span id="name">{{name}}</span><span id="mode">repos</span></header>
|
||||
<section id="stage"><div id="content"><h1>Bonjour.</h1><p>À votre écoute.</p></div></section>
|
||||
<section id="wave"><canvas id="waveCanvas"></canvas></section>
|
||||
<footer class="alfred-controls" aria-label="Contrôles audio">
|
||||
<button id="speakerMute" class="audio-toggle" type="button" aria-label="Couper le haut-parleur" aria-pressed="false" title="Couper le haut-parleur">🔊</button>
|
||||
<label class="volume-label" for="volumeSlider">Volume</label>
|
||||
<input id="volumeSlider" type="range" min="0" max="100" step="1" value="70" aria-label="Volume sonore">
|
||||
<output id="volumeValue" for="volumeSlider">70 %</output>
|
||||
<span class="controls-separator" aria-hidden="true"></span>
|
||||
<button id="micMute" class="audio-toggle" type="button" aria-label="Couper le microphone" aria-pressed="false" title="Couper le microphone">🎙️</button>
|
||||
</footer>
|
||||
</main>
|
||||
<script src="/static/js/alfred.js"></script>
|
||||
<script src="/static/js/alfred-controls.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user