feat(voice): playback-speed toggle (1x/1.5x/2x) with per-user default
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
// Persists the preferred voice-message playback rate across sessions.
|
||||
// localStorage is fine here — non-sensitive, single source of truth per
|
||||
// device, no cross-device sync needed.
|
||||
|
||||
const KEY = 'chatapp:voice-speed';
|
||||
const ALLOWED = [1, 1.5, 2] as const;
|
||||
export type VoiceSpeed = (typeof ALLOWED)[number];
|
||||
|
||||
export function getVoiceSpeed(): VoiceSpeed {
|
||||
try {
|
||||
const raw = window.localStorage.getItem(KEY);
|
||||
if (!raw) return 1;
|
||||
const parsed = Number(raw);
|
||||
if (ALLOWED.includes(parsed as VoiceSpeed)) return parsed as VoiceSpeed;
|
||||
} catch {
|
||||
/* localStorage unavailable */
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
export function setVoiceSpeed(speed: VoiceSpeed): void {
|
||||
try {
|
||||
window.localStorage.setItem(KEY, String(speed));
|
||||
} catch {
|
||||
/* localStorage unavailable — best effort */
|
||||
}
|
||||
}
|
||||
|
||||
export const VOICE_SPEEDS = ALLOWED;
|
||||
Reference in New Issue
Block a user